kirash4

LPD8806 Strip Test

Jun 9th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. #define NUM_LEDS 24
  4. #define DATA_PIN 11
  5. #define CLOCK_PIN 13
  6.  
  7. volatile uint8_t col = 0;
  8.  
  9. // Define the array of leds
  10. CRGB leds[NUM_LEDS];
  11.  
  12. void setup() {
  13.   LEDS.addLeds<LPD8806,DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS).setDither(DISABLE_DITHER);
  14.   memset(leds, 0,  NUM_LEDS * sizeof(struct CRGB));
  15.   LEDS.setBrightness(64);
  16. }
  17.  
  18. void loop() {
  19.   // First slide the led in one direction
  20.   for(int i = 0; i < NUM_LEDS; i++) {
  21.     switch(col) {
  22.       case 0: leds[i] = CRGB::Red; break;
  23.       case 1: leds[i] = CRGB::Green; break;
  24.       case 2: leds[i] = CRGB::Blue; break;
  25.     }
  26.     // Show the leds
  27.     FastLED.show();
  28.     leds[i] = CRGB::Black;
  29.     delay(50);
  30.   }
  31.  
  32.   // Now go in the other direction.  
  33.   for(int i = NUM_LEDS - 2; i >= 0; i--) {
  34.     switch(col) {
  35.       case 0: leds[i] = CRGB::Red; break;
  36.       case 1: leds[i] = CRGB::Green; break;
  37.       case 2: leds[i] = CRGB::Blue; break;
  38.     }
  39.     // Show the leds
  40.     FastLED.show();
  41.     leds[i] = CRGB::Black;
  42.     delay(50);
  43.   }
  44.   FastLED.show();
  45.   col++;
  46.   if (col > 2) col = 0;
  47.   delay(250);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment