Skip to content

Instantly share code, notes, and snippets.

@ssozonoff
Created December 13, 2014 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssozonoff/9d5df46b54759f7572b0 to your computer and use it in GitHub Desktop.
Save ssozonoff/9d5df46b54759f7572b0 to your computer and use it in GitHub Desktop.
#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