//Load NeoPixel library
#include
//Digital output pun and number of LEDs on string
#define PIN 6
#define NUMPIXELS 12
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
// Initialize values used.
// brightVal is how long LEDs are on.
// darkVal is how long before next lightning effect
// delayVal is the delay between lightning effect blinks
// lightVal is how bright each of the flashes are
// flashVal is how many time the lightning effect flashes
// blinkTimes is how many times the lightning effect flashes
// r, g, b are used to set the RGB value of the LED
// r, g, b is assigned the value generated from the lightVal variable. If you want different RGB values, assign different values to r, g, b.
int brightVal=0;
int darkVal=0;
int delayVal=0;
int lightVal=0;
int flashVal=0;
int blinkTimes=0;
int r=0;
int g=0;
int b=0;
void setup(){
pixels.begin();
}
void loop() {
// LEDs remain dark between 1000ms and 10000ms
darkVal=random(1000,10000);
// LEDs will flash between 2 and 21 times
flashVal=random(2,21);
for(int blinkTimes=0;blinkTimes<=flashVal;blinkTimes++){
// LEDs will be a RGB value of 0 to 255 to vary brightness
lightVal=random(0,255);
// lightVal set to r, g, b. Can be changed to individual values for other colors
r=lightVal;
g=lightVal;
b=lightVal;
// LEDs will remain on between 20ms and 200ms
brightVal=random(20,200);
// Flashes will be delayed between 20ms and 500ms
delayVal=random(20,500);
pixels.setPixelColor(0,pixels.Color(r,g,b));
pixels.show();
pixels.setPixelColor(1,pixels.Color(r,g,b));
pixels.show();
pixels.setPixelColor(2,pixels.Color(r,g,b));
pixels.show();
pixels.setPixelColor(3,pixels.Color(r,g,b));
pixels.show();
pixels.setPixelColor(4,pixels.Color(r,g,b));
pixels.show();
pixels.setPixelColor(5,pixels.Color(r,g,b));
pixels.show();
pixels.setPixelColor(6,pixels.Color(r,g,b));
pixels.show();
pixels.setPixelColor(7,pixels.Color(r,g,b));
pixels.show();
pixels.setPixelColor(8,pixels.Color(r,g,b));
pixels.show();
pixels.setPixelColor(9,pixels.Color(r,g,b));
pixels.show();
pixels.setPixelColor(10,pixels.Color(r,g,b));
pixels.show();
pixels.setPixelColor(11,pixels.Color(r,g,b));
pixels.show();
delay(brightVal);
pixels.setPixelColor(0,pixels.Color(0,0,0));
pixels.show();
pixels.setPixelColor(1,pixels.Color(0,0,0));
pixels.show();
pixels.setPixelColor(2,pixels.Color(0,0,0));
pixels.show();
pixels.setPixelColor(3,pixels.Color(0,0,0));
pixels.show();
pixels.setPixelColor(4,pixels.Color(0,0,0));
pixels.show();
pixels.setPixelColor(5,pixels.Color(0,0,0));
pixels.show();
pixels.setPixelColor(6,pixels.Color(0,0,0));
pixels.show();
pixels.setPixelColor(7,pixels.Color(0,0,0));
pixels.show();
pixels.setPixelColor(8,pixels.Color(0,0,0));
pixels.show();
pixels.setPixelColor(9,pixels.Color(0,0,0));
pixels.show();
pixels.setPixelColor(10,pixels.Color(0,0,0));
pixels.show();
pixels.setPixelColor(11,pixels.Color(0,0,0));
pixels.show();
delay(delayVal);
}
delay(darkVal);
}
Pages: 1 2
Leave a Reply