Ceci est une ancienne révision du document !


Code Arduino pour la boîte Ouvert/fermé

/*  Sketch created for an Open/closed sign for Pop [lab] Montreuil

    An Arduino connects to 2 Pololu Led strips, 12 leds long
    A switch toggles between which one is lit 
    

    Fallback mode only back and forward

    mh8 - December 2017

*/

#include <PololuLedStrip.h>

// Create 2 ledStrip objects on pin 10 & 12
PololuLedStrip<12> ledStripOpen;
PololuLedStrip<10> ledStripClosed;

// Create two buffers to hold the colors on the ledStrips
#define LED_COUNT 12
rgb_color colorsOpen[LED_COUNT];
rgb_color colorsClosed[LED_COUNT];
rgb_color colors[LED_COUNT];
rgb_color colorsOff[LED_COUNT];

// A switch button toggles On/Off
const uint8_t buttonPin = 2;
uint8_t buttonState = 0;

// A push button selects between different modes
// Use a 4.7K pullup resistor to connect the pin to the 5V
const uint8_t switchPin = 4;
uint8_t switchSelect = 0;

//Variable for delays (can go up to 65536 on 2 bytes)
uint16_t interval = 100;

//Variable defining maximum number of modes. Count starts at 0.
//This value should be 1 more than the number of the last mode
uint8_t maxModes = 3;

void setup() {

  pinMode(buttonPin, INPUT);
  pinMode(switchPin, INPUT);

  Serial.begin(115200);

  //Initialize all arrays to off
  for (int i = 0; i < LED_COUNT; i++)
  {
    colors[i] = colorsOff[i] = rgb_color(0, 0, 0);
  }
}

void loop() {

 //In this mode we need to know if we address the OPEN or the CLOSED ledStrip
  int buttonState = digitalRead(buttonPin);

  //Define two random colors to use in the back and foward movement
  rgb_color colorOne = rgb_color(random(255), random(255), random(255));
  rgb_color colorTwo = rgb_color(random(255), random(255), random(255));

  //FORWARD Movement
  for (uint8_t i = 0; i < LED_COUNT; i++) {
    colors[i] = colorOne;
    if (buttonState == 1) {
      // Write to OPEN not to CLOSED
      ledStripOpen.write(colors, LED_COUNT);
      ledStripClosed.write(colorsOff, LED_COUNT);
    }

    else if (buttonState == 0) {
      // Write to CLOSED not to OPEN
      ledStripClosed.write(colors, LED_COUNT);
      ledStripOpen.write(colorsOff, LED_COUNT);
    }
    delay(interval);
  }

  //BACK Movement
  for (uint8_t i = LED_COUNT; i > 0; i--) {
    colors[i] = colorTwo;
    if (buttonState == 1) {
      // Write to OPEN not to CLOSED
      ledStripOpen.write(colors, LED_COUNT);
    }

    else if (buttonState == 0) {
      // Write to CLOSED not to OPEN
      ledStripClosed.write(colors, LED_COUNT);
    }
    delay(interval);
  }
}

void writetoLeds() {
  int buttonState = digitalRead(buttonPin);

  if (buttonState == 1) {
    // Turn ON OPEN led strip turn OFF CLOSED led strip
    for (uint8_t i = 0; i < LED_COUNT; i++)
    {
      colorsOpen[i] = colors[i];
      colorsClosed[i] = colorsOff[i];
    }
  }

  else if (buttonState == 0) {
    // Turn OFF OPEN led strip turn ON CLOSED led strip
    for (uint8_t i = 0; i < LED_COUNT; i++)
    {
      colorsOpen[i] = colorsOff[i];
      colorsClosed[i] = colors[i];
    }
  }

  // Write to the led strips
  ledStripOpen.write(colorsOpen, LED_COUNT);
  ledStripClosed.write(colorsClosed, LED_COUNT);

  delay(10);
}

Fichiers