Last active
December 22, 2015 06:51
-
-
Save ayumi/622d9b7cb100d60658b9 to your computer and use it in GitHub Desktop.
portable rainbow (digispark + light_ws2812)
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
// Dependency: | |
// light_ws2812 | |
// https://github.com/cpldcpu/light_ws2812 | |
// --- | |
// if you have USB 3.0 ports, you might need a USB 2.0 hub to program this. | |
// use the cRGB struct hsv method | |
#define USE_HSV | |
#include <WS2812.h> | |
#define NUM_LEDS 25 | |
#define outputPin 0 | |
#define UPDATES_PER_SECOND 20 | |
WS2812 LED(NUM_LEDS); | |
cRGB my_crgb; | |
int h = 0; //stores 0 to 614 | |
int x = 2; | |
byte steps = 1; //number of hues we skip in a 360 range per update | |
byte sat = 255; | |
byte val = 220; | |
void setup() { | |
// Power up safety delay | |
delay(1000); | |
LED.setOutput(outputPin); | |
} | |
void loop() { | |
int inner_h = h; | |
for( int i = 0; i < NUM_LEDS; i++ ) { | |
if (i%2) { | |
inner_h += (i/2)*x; | |
} | |
if(inner_h >= 360) | |
{ | |
inner_h %= 360; | |
} | |
my_crgb.SetHSV(inner_h, sat, val); | |
LED.set_crgb_at(i, my_crgb); | |
} | |
h += steps; | |
if(h >= 360) | |
{ | |
h %= 360; | |
} | |
LED.sync(); | |
delay(1000 / UPDATES_PER_SECOND); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment