Gestion d'une bande de led RVB

 

Exemple de code et librairie :

basicPatterns.zip

Exemples d'utilisation

http://www.instructables.com/id/Controllable-RGB-LED-system-for-your-home-or-offic/

Code source

  1.  /*
  2.  This is the most basic demonstration code of using HL1606-based digital LED strips.
  3.  The HL1606 chips are not very 'smart' and do not have built in PWM control. (Although
  4.  there is a fading ability, its not that useful)
  5.  
  6.  We have a few examples of using the setLEDcolor() and writeStrip() command that will allow changing the strip around
  7.  
  8.  public domain
  9.  */
  10.  // HL1606strip is an adaptation of LEDstrip from http://code.google.com/p/ledstrip/
  11.  #include "HL1606strip.h"
  12.  
  13.  #define STRIP_S 12
  14.  #define STRIP_D 11
  15.  #define STRIP_C 13
  16.  #define STRIP_L 10
  17.  
  18.  // Pin S is not really used in this demo since it doesnt use the built in PWM fade
  19.  // The last argument is the number of LEDs in the strip. Each chip has 2 LEDs, and the number
  20.  // of chips/LEDs per meter varies so make sure to count them! if you have the wrong number
  21.  // the strip will act a little strangely, with the end pixels not showing up the way you like
  22.  
  23.  HL1606strip strip = HL1606strip(STRIP_D, STRIP_S, STRIP_L, STRIP_C, 32);
  24.  
  25.  void setup(void) {
  26.   // nothing to do!
  27.  }
  28.  
  29.  void loop(void) {
  30.   // first argument is the color, second is the delay in milliseconds between commands
  31.   // test all the LED colors with a wipe
  32.   colorWipe(RED, 20);
  33.   colorWipe(YELLOW, 20);
  34.   colorWipe(GREEN, 20);
  35.   colorWipe(TEAL, 20);
  36.   colorWipe(BLUE, 20);
  37.   colorWipe(VIOLET, 20);
  38.   colorWipe(WHITE, 20);
  39.   colorWipe(BLACK, 20);
  40.  
  41.   // then a chase
  42.  
  43.   chaseSingle(RED, 20);
  44.   chaseSingle(YELLOW, 20);
  45.   chaseSingle(GREEN, 20);
  46.   chaseSingle(TEAL, 20);
  47.   chaseSingle(VIOLET, 20);
  48.   chaseSingle(WHITE, 20);
  49.  
  50.   // a colorcycle party!
  51.   rainbowParty(40);
  52.  }
  53.  
  54.  /**********************************************/
  55.  // scroll a rainbow!
  56.  
  57.  void rainbowParty(uint8_t wait) {
  58.   uint8_t i, j;
  59.  
  60.   for (i=0; i< strip.numLEDs(); i+=6) {
  61.   // initialize strip with 'rainbow' of colors
  62.   strip.setLEDcolor(i, RED);
  63.   strip.setLEDcolor(i+1, YELLOW);
  64.   strip.setLEDcolor(i+2, GREEN);
  65.   strip.setLEDcolor(i+3, TEAL);
  66.   strip.setLEDcolor(i+4, BLUE);
  67.   strip.setLEDcolor(i+5, VIOLET);
  68.   }
  69.   strip.writeStrip();
  70.  
  71.   for (j=0; j < strip.numLEDs(); j++) {
  72.   // now set every LED to the *next* LED color (cycling)
  73.   uint8_t savedcolor = strip.getLEDcolor(0);
  74.   for (i=1; i < strip.numLEDs(); i++) {
  75.   strip.setLEDcolor(i-1, strip.getLEDcolor(i)); // move the color back one.
  76.   }
  77.   // cycle the first LED back to the last one
  78.   strip.setLEDcolor(strip.numLEDs()-1, savedcolor);
  79.   strip.writeStrip();
  80.   delay(wait);
  81.   }
  82.  }
  83.  // turn everything off (fill with BLACK)
  84.  
  85.  void stripOff(void) {
  86.   // turn all LEDs off!
  87.   for (uint8_t i=0; i < strip.numLEDs(); i++) {
  88.   strip.setLEDcolor(i, BLACK);
  89.   }
  90.   strip.writeStrip();
  91.  }
  92.  
  93.  // have one LED 'chase' around the strip
  94.  void chaseSingle(uint8_t color, uint8_t wait) {
  95.   uint8_t i;
  96.   // turn everything off
  97.   for (i=0; i< strip.numLEDs(); i++) {
  98.   strip.setLEDcolor(i, BLACK);
  99.   }
  100.   for (i=0; i < strip.numLEDs(); i++) {
  101.   strip.setLEDcolor(i, color);
  102.   if (i != 0) {
  103.   // make the LED right before this one OFF
  104.   strip.setLEDcolor(i-1, BLACK);
  105.   }
  106.   strip.writeStrip();
  107.   delay(wait);
  108.   }
  109.   // turn off the last LED before leaving
  110.   strip.setLEDcolor(strip.numLEDs() - 1, BLACK);
  111.  }
  112.  
  113.  // fill the entire strip, with a delay between each pixel for a 'wipe' effect
  114.  void colorWipe(uint8_t color, uint8_t wait) {
  115.   uint8_t i;
  116.   for (i=0; i < strip.numLEDs(); i++) {
  117.   strip.setLEDcolor(i, color);
  118.   strip.writeStrip();
  119.   delay(wait);
  120.   }
  121.  }