Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Lightnings is a program that lets you make an LED strip look like a 1D cloud of lightning
- //
- // Original by: Daniel Wilson, 2014
- //
- // Modified by: Andrew Tuline 2015
- //
- // This modified version creates lightning along various sections of the strip.
- //
- #include "FastLED.h"
- #define NUM_LEDS 30
- #define LED_DT 12
- #define LED_CK 11
- #define COLOR_ORDER GRB
- #define CHIPSET WS2812
- #define FREQUENCY 50 // controls the interval between strikes
- #define FLASHES 8 // the upper limit of flashes per strike
- #define BRIGHTNESS 255
- CRGB leds[NUM_LEDS];
- unsigned int dimmer = 1;
- uint8_t ledstart; // Starting location of a flash
- uint8_t ledlen; // Length of a flash
- void setup() {
- delay(1000); // allows reprogramming if accidently blowing power w/leds
- LEDS.addLeds<CHIPSET, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2812
- // LEDS.addLeds<CHIPSET, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2801 or APA102
- FastLED.setBrightness(BRIGHTNESS);
- } // setup()
- void loop() {
- ledstart = random8(NUM_LEDS); // Determine starting location of flash
- ledlen = random8(NUM_LEDS-ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1)
- for (int flashCounter = 0; flashCounter < random8(3,FLASHES); flashCounter++) {
- if(flashCounter == 0) dimmer = 5; // the brightness of the leader is scaled down by a factor of 5
- else dimmer = random8(1,3); // return strokes are brighter than the leader
- fill_solid(leds+ledstart,ledlen,CHSV(255, 0, 255/dimmer));
- FastLED.show(); // Show a section of LED's
- delay(random8(4,10)); // each flash only lasts 4-10 milliseconds
- fill_solid(leds+ledstart,ledlen,CHSV(255,0,0)); // Clear the section of LED's
- FastLED.show();
- if (flashCounter == 0) delay (150); // longer delay until next flash after the leader
- delay(50+random8(100)); // shorter delay between strokes
- } // for()
- delay(random8(FREQUENCY)*100); // delay between strikes
- } // loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement