-
-
Save hsiboy/851404307232801cb79e to your computer and use it in GitHub Desktop.
// 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 | |
} | |
You need to define FREQUENCY at the top of the file and set it to a value that produces the effect you want.
#define FREQUENCY 2
For example.
Hi there,
Even if I define FREQUENCY it stills does not compile. Here is what I have:
#include <FastLED.h>
#define LED_PIN 4 // hardware SPI pin SCK
#define NUM_LEDS 5
#define COLOR_ORDER RGB
#define LED_TYPE WS2811
#define MAX_BRIGHTNESS 200 // watch the power!
#define FPS 50;
#define FLASHES 8;
#define FREQUENCY 2;
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 strokes
}
delay(random8(FREQUENCY) * 100); // delay between strikes
}
Thanks in advance!
Hi, what is the error message at compile time?
Can i get a wiring diagram, I would love to do this and put it in my home be hided some cotton balls
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.
Frequency not defined