Advertisement
steveof2620

FastLED Lightning Effect

Dec 15th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // stolen from https://github.com/fibonacci162
  2.  
  3. #include <FastLED.h>
  4.  
  5. #define LED_PIN 13                           // hardware SPI pin SCK
  6. #define NUM_LEDS 250
  7. #define COLOR_ORDER RGB
  8. #define LED_TYPE WS2811
  9. #define MAX_BRIGHTNESS 255                   // watch the power!
  10. #define FPS 50;
  11. #define FLASHES 8;
  12.  
  13. struct CRGB leds[NUM_LEDS];
  14.  
  15. unsigned int dimmer = 1;
  16.  
  17. void setup() {
  18.   delay(3000);
  19.   LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  20.   FastLED.setBrightness(MAX_BRIGHTNESS);
  21. }
  22.  
  23. // The first "flash" in a bolt of lightning is the "leader." The leader
  24. // is usually duller and has a longer delay until the next flash. Subsequent
  25. // flashes, the "strokes," are brighter and happen at shorter intervals.
  26.  
  27. void loop()
  28. {
  29.   for (int flashCounter = 0; flashCounter < random8(3,FLASHES); flashCounter++)
  30.   {
  31.     if(flashCounter == 0) dimmer = 5;     // the brightness of the leader is scaled down by a factor of 5
  32.     else dimmer = random8(1,3);           // return strokes are brighter than the leader
  33.    
  34.     FastLED.showColor(CHSV(255, 0, 255/dimmer));
  35.     delay(random8(4,10));                 // each flash only lasts 4-10 milliseconds
  36.     FastLED.showColor(CHSV(255, 0, 0));
  37.    
  38.     if (flashCounter == 0) delay (150);   // longer delay until next flash after the leader
  39.     delay(50+random8(100));               // shorter delay between strokes  
  40.   }
  41.   delay(random8(FREQUENCY)*100);          // delay between strikes
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement