Last active
October 25, 2023 10:08
-
-
Save hsiboy/851404307232801cb79e to your computer and use it in GitHub Desktop.
WS2811 - Lightning effect - FastLed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// stolen from https://github.com/fibonacci162 | |
#include <FastLED.h> | |
#define LED_PIN 13 // hardware SPI pin SCK | |
#define NUM_LEDS 250 | |
#define COLOR_ORDER RGB | |
#define LED_TYPE WS2811 | |
#define MAX_BRIGHTNESS 255 // watch the power! | |
#define FPS 50 | |
#define FLASHES 8 | |
#define FREQUENCY 2 // delay between strikes | |
struct CRGB leds[NUM_LEDS]; | |
unsigned int dimmer = 1; | |
void setup() { | |
delay(3000); | |
LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); | |
FastLED.setBrightness(MAX_BRIGHTNESS); | |
} | |
// The first "flash" in a bolt of lightning is the "leader." The leader | |
// is usually duller and has a longer delay until the next flash. Subsequent | |
// flashes, the "strokes," are brighter and happen at shorter intervals. | |
void loop() | |
{ | |
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 | |
FastLED.showColor(CHSV(255, 0, 255/dimmer)); | |
delay(random8(4,10)); // each flash only lasts 4-10 milliseconds | |
FastLED.showColor(CHSV(255, 0, 0)); | |
if (flashCounter == 0) delay (150); // longer delay until next flash after the leader | |
delay(50+random8(100)); // shorter delay between strikes | |
} | |
delay(random8(FREQUENCY)*100); // delay between strikes | |
} | |
Can i get a wiring diagram, I would love to do this and put it in my home be hided some cotton balls
As the code is written, it outputs the data on pin 13 of the Arduino.
So connect the data line of a string or tape of WS2811 LEDs to pin 13, connect the ground to the ground on the Arduino. Connect the positive of the LEDs to a suitable power supply and connect the Arduino to its own power supply.
Lots of tutorials for wiring "neo pixels" will show you how.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can i get a wiring diagram, I would love to do this and put it in my home be hided some cotton balls