first implementation of 'chase';

new implementation of breathe that seems less blinky (but looks less nice)
pull/18/head
Jesse Vincent 10 years ago
parent 6a35d6fe03
commit fb15fba790

@ -5,12 +5,13 @@ WS2812 LED(LED_COUNT);
int led_mode; int led_mode;
int last_led_mode; int last_led_mode;
int pos=0;
cRGB led_off; cRGB led_off;
cRGB led_steady; cRGB led_steady;
cRGB led_blue;
cRGB led_dark_blue;
cRGB led_breathe; cRGB led_breathe;
@ -20,9 +21,18 @@ void setup_leds() {
led_off.r=0; led_off.r=0;
led_off.g=0; led_off.g=0;
led_off.b=0; led_off.b=0;
led_steady.r=30; led_steady.r=160;
led_steady.g=30; led_steady.g=160;
led_steady.b=30; led_steady.b=160;
led_blue.r=0;
led_blue.g=0;
led_blue.b=255;
led_dark_blue.r=0;
led_dark_blue.g=0;
led_dark_blue.b=127;
LED.setOutput(LED_DATA_PIN); LED.setOutput(LED_DATA_PIN);
LED.setColorOrderRGB(); // Uncomment for RGB color order LED.setColorOrderRGB(); // Uncomment for RGB color order
led_mode=LED_MODE_STEADY; led_mode=LED_MODE_STEADY;
@ -66,6 +76,12 @@ void set_all_leds_to(cRGB color) {
} }
} }
int brightness = 0; // how bright the LED is
int fadeAmount = 1; // how many points to fade the LED by
int chase_pixels = 1;
int chase_threshold = 6;
int current_chase_counter=0;
void update_leds() { void update_leds() {
if (led_mode != last_led_mode) { if (led_mode != last_led_mode) {
initialize_led_mode(led_mode); initialize_led_mode(led_mode);
@ -74,16 +90,44 @@ void update_leds() {
} else if (led_mode == LED_MODE_HEATMAP) { } else if (led_mode == LED_MODE_HEATMAP) {
} else if (led_mode == LED_MODE_BREATHE) { } else if (led_mode == LED_MODE_BREATHE) {
// algorithm from http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ // algorithm from http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
int brightness = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0; // int brightness = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0;
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 160) {
fadeAmount = -fadeAmount ;
}
led_breathe.r=brightness; led_breathe.r=brightness;
led_breathe.g=brightness; led_breathe.g=brightness;
led_breathe.b=brightness; led_breathe.b=brightness;
set_all_leds_to(led_breathe);
LED.sync();
} else if (led_mode == LED_MODE_RAINBOW) { } else if (led_mode == LED_MODE_RAINBOW) {
} else if (led_mode == LED_MODE_CHASE) { } else if (led_mode == LED_MODE_CHASE) {
} else if (led_mode == LED_MODE_STEADY) { if(current_chase_counter++<chase_threshold) {
return;
}
current_chase_counter=0;
LED.set_crgb_at(pos-chase_pixels,led_off);
LED.set_crgb_at(pos,led_dark_blue);
pos+=chase_pixels;
if (pos>LED_COUNT||pos<0) {
chase_pixels = -chase_pixels;
pos+=chase_pixels;
} }
LED.set_crgb_at(pos,led_blue);
LED.sync();
} else if (led_mode == LED_MODE_STEADY) {
LED.sync(); LED.sync();
}
last_led_mode = led_mode; last_led_mode = led_mode;
} }

Loading…
Cancel
Save