From d4f57871fefe65174d0abdf6ea276cd2b96c5f6e Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 4 Apr 2015 13:31:59 -0700 Subject: [PATCH] Rainbow effect updates --- led_control.cpp | 51 +++++++++++++++++++++++++++++++++---------------- led_control.h | 8 +++++--- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/led_control.cpp b/led_control.cpp index 3dd174b1..84d42478 100644 --- a/led_control.cpp +++ b/led_control.cpp @@ -24,10 +24,12 @@ cRGB led_breathe; cRGB rainbow; int rainbow_hue = 0; //stores 0 to 614 byte rainbow_steps = 1; //number of hues we skip in a 360 range per update +byte rainbow_wave_steps =1; //number of hues we skip in a 360 range per update byte rainbow_saturation = 255; byte rainbow_value = 190; +long rainbow_wave_ticks = 1; //delays between update long rainbow_ticks = 5; //delays between update long rainbow_current_ticks =0; int breathe_brightness = 0; // how bright the LED is @@ -59,7 +61,7 @@ void setup_leds() { LED.setOutput(LED_DATA_PIN); LED.setColorOrderGRB(); // Uncomment for RGB color order - led_mode = LED_MODE_RAINBOW; + led_mode = LED_MODE_RAINBOW_WAVE; } byte key_to_led(byte row, byte col) { @@ -84,6 +86,7 @@ void initialize_led_mode(int mode) { } else if (mode == LED_MODE_BREATHE) { } else if (mode == LED_MODE_RAINBOW) { + } else if (mode == LED_MODE_RAINBOW_WAVE) { } else if (mode == LED_MODE_CHASE) { } else if (mode == LED_MODE_STEADY) { set_all_leds_to(led_steady); @@ -121,21 +124,12 @@ void update_leds() { } else if (led_mode == LED_MODE_HEATMAP) { } else if (led_mode == LED_MODE_BREATHE) { led_effect_breathe_update(); - - - } else if (led_mode == LED_MODE_RAINBOW) { - - led_effect_rainbow_update(); - - - + } else if (led_mode == LED_MODE_RAINBOW_WAVE) { + led_effect_rainbow_wave_update(); } else if (led_mode == LED_MODE_CHASE) { - led_effect_chase_update(); - - } else if (led_mode == LED_MODE_STEADY) { led_effect_steady_update(); @@ -164,10 +158,7 @@ void led_effect_breathe_update() { } - - led_breathe.r = breathe_brightness * 0; - led_breathe.g = breathe_brightness *0.5; - led_breathe.b = breathe_brightness * 0; + led_breathe.SetHSV(200, 255, breathe_brightness); set_all_leds_to(led_breathe); LED.sync(); } @@ -218,3 +209,31 @@ void led_effect_rainbow_update() { +void led_effect_rainbow_wave_update() { + + + if (rainbow_current_ticks++ < rainbow_wave_ticks) { + return; + } else { rainbow_current_ticks = 0; } + + + for (int i = 0; i < LED_COUNT; i++) { + + int key_hue = rainbow_hue +16*(i/4); + if (key_hue > 360) { + key_hue %= 360; + } + rainbow.SetHSV(key_hue, rainbow_saturation, rainbow_value); + LED.set_crgb_at(i,rainbow); + + + + } + rainbow_hue += rainbow_wave_steps; + if (rainbow_hue > 360) { + rainbow_hue %= 360; + } + LED.sync(); +} + + diff --git a/led_control.h b/led_control.h index 06b43aab..86c1708f 100644 --- a/led_control.h +++ b/led_control.h @@ -2,13 +2,14 @@ #define LED_CONTROL_H #include "WS2812.h" -#define LED_MODES 6 +#define LED_MODES 7 #define LED_MODE_OFF 0 #define LED_MODE_STEADY 1 #define LED_MODE_BREATHE 2 #define LED_MODE_RAINBOW 3 -#define LED_MODE_HEATMAP 4 -#define LED_MODE_CHASE 5 +#define LED_MODE_RAINBOW_WAVE 4 +#define LED_MODE_HEATMAP 5 +#define LED_MODE_CHASE 6 #define LED_DATA_PIN 4 @@ -43,6 +44,7 @@ void led_Effect_heatmap_init(); void led_effect_breathe_update(); void led_effect_rainbow_update(); +void led_effect_rainbow_wave_update(); void led_effect_chase_update(); void led_effect_steady_update(); void led_Effect_heatmap_update();