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 rainbow mode

    mh8 - February 2018

*/

#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 = 10;

//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);

  // Update the colors (comes from LedStripRainbow example)
  uint16_t time = millis() >> 2;
  for (uint16_t i = 0; i < LED_COUNT; i++)
  {
    byte x = (time >> 2) - (i << 3);
    colors[i] = hsvToRgb((uint32_t)x * 359 / 256, 255, 255);
  }

  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);

}

// Comes from LedStripRainbow example
// Converts a color from HSV to RGB.
// h is hue, as a number between 0 and 360.
// s is the saturation, as a number between 0 and 255.
// v is the value, as a number between 0 and 255.
rgb_color hsvToRgb(uint16_t h, uint8_t s, uint8_t v)
{
  uint8_t f = (h % 60) * 255 / 60;
  uint8_t p = (255 - s) * (uint16_t)v / 255;
  uint8_t q = (255 - f * (uint16_t)s / 255) * (uint16_t)v / 255;
  uint8_t t = (255 - (255 - f) * (uint16_t)s / 255) * (uint16_t)v / 255;
  uint8_t r = 0, g = 0, b = 0;
  switch ((h / 60) % 6) {
    case 0: r = v; g = t; b = p; break;
    case 1: r = q; g = v; b = p; break;
    case 2: r = p; g = v; b = t; break;
    case 3: r = p; g = q; b = v; break;
    case 4: r = t; g = p; b = v; break;
    case 5: r = v; g = p; b = q; break;
  }
  return rgb_color(r, g, b);
}

Fichiers

Pour l'instant le panneau n'est pas stabilisé (fallback mode, cf code ci-dessus).

Le fichier .ino sera mis en ligne lorsque le code sera stabilisé et présentera plusieurs affichages différents.