Advertisement
atuline

Lightnings for FastLED

Jul 14th, 2015
2,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. //  Lightnings is a program that lets you make an LED strip look like a 1D cloud of lightning
  2. //
  3. //  Original by: Daniel Wilson, 2014
  4. //
  5. //  Modified by: Andrew Tuline 2015
  6. //
  7. //  This modified version creates lightning along various sections of the strip.
  8. //
  9.  
  10. #include "FastLED.h"
  11.  
  12. #define NUM_LEDS      30
  13. #define LED_DT        12
  14. #define LED_CK        11
  15. #define COLOR_ORDER   GRB
  16. #define CHIPSET       WS2812
  17. #define FREQUENCY     50                // controls the interval between strikes
  18. #define FLASHES       8                 // the upper limit of flashes per strike
  19. #define BRIGHTNESS    255
  20.  
  21. CRGB leds[NUM_LEDS];
  22.  
  23. unsigned int dimmer = 1;
  24.  
  25. uint8_t ledstart;                      // Starting location of a flash
  26. uint8_t ledlen;                        // Length of a flash
  27.  
  28.  
  29. void setup() {
  30.   delay(1000);                           // allows reprogramming if accidently blowing power w/leds
  31.   LEDS.addLeds<CHIPSET, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);  // Use this for WS2812
  32. //  LEDS.addLeds<CHIPSET, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS);  // Use this for WS2801 or APA102
  33.   FastLED.setBrightness(BRIGHTNESS);
  34. } // setup()
  35.  
  36.  
  37. void loop() {
  38.   ledstart = random8(NUM_LEDS);           // Determine starting location of flash
  39.   ledlen = random8(NUM_LEDS-ledstart);    // Determine length of flash (not to go beyond NUM_LEDS-1)
  40.   for (int flashCounter = 0; flashCounter < random8(3,FLASHES); flashCounter++) {
  41.     if(flashCounter == 0) dimmer = 5;     // the brightness of the leader is scaled down by a factor of 5
  42.     else dimmer = random8(1,3);           // return strokes are brighter than the leader
  43.     fill_solid(leds+ledstart,ledlen,CHSV(255, 0, 255/dimmer));
  44.     FastLED.show();                       // Show a section of LED's
  45.     delay(random8(4,10));                 // each flash only lasts 4-10 milliseconds
  46.     fill_solid(leds+ledstart,ledlen,CHSV(255,0,0));   // Clear the section of LED's
  47.     FastLED.show();    
  48.     if (flashCounter == 0) delay (150);   // longer delay until next flash after the leader
  49.     delay(50+random8(100));               // shorter delay between strokes  
  50.   } // for()
  51.   delay(random8(FREQUENCY)*100);          // delay between strikes
  52. } // loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement