-
-
Save ssozonoff/9d5df46b54759f7572b0 to your computer and use it in GitHub Desktop.
This file contains 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
#include <WS2812.h> | |
#define outputPin 13 // Digital output pin (default: 7) | |
#define LEDCount 50 // Number of LEDs to drive (default: 9) | |
WS2812 LED(LEDCount); | |
cRGB value; | |
cRGB previousValue; | |
byte base_r = 80; | |
byte base_g = 80; | |
byte base_b = 0; | |
byte p = random(50); | |
byte previous_position = 0; | |
long loopc = 0; | |
void setup() { | |
LED.setOutput(outputPin); // Digital Pin 7 | |
/* You may uncomment one of the following three lines to switch | |
to a different data transmission sequence for your addressable LEDs. | |
(These functions can be used at any point in your program as needed.) */ | |
LED.setColorOrderRGB(); // Uncomment for RGB color order | |
refresh(); | |
} | |
void refresh() { | |
byte i = 0; | |
while (i < LEDCount) { | |
if ((i % 2) == 0) { | |
value.b = 0; | |
value.g = base_g; | |
value.r = 0; | |
} else { | |
value.b = 0; | |
value.g = 0; | |
value.r = base_r; | |
} | |
LED.set_crgb_at(i, value); // Set value at LED found at index i | |
i++; | |
} | |
LED.sync(); // Sends the data to the LEDs | |
} | |
void blink() { | |
p = random(50); | |
previousValue = LED.get_crgb_at(p); | |
value.b = 255; | |
value.g = 255; | |
value.r = 255; | |
LED.set_crgb_at(p, value); | |
LED.sync(); // Sends the data to the LEDs | |
delay(25); | |
LED.set_crgb_at(p, previousValue); | |
LED.sync(); // Sends the data to the LEDs | |
} | |
void loop() { | |
blink(); | |
delay(random(100, 2000)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment