bidirectional running lights effect

This commit is contained in:
fishbone-git 2020-02-18 21:28:46 +01:00
parent 9c3e7b9ec0
commit cb0452964e
2 changed files with 23 additions and 6 deletions

View File

@ -426,13 +426,15 @@ uint16_t WS2812FX::mode_theater_chase_rainbow(void) {
/* /*
* Running lights effect with smooth sine transition base. * Running lights effect with smooth sine transition base.
*/ */
uint16_t WS2812FX::running_base(bool saw) { uint16_t WS2812FX::running_base(bool saw, bool dual=false) {
uint8_t x_scale = SEGMENT.intensity >> 2; uint8_t x_scale = SEGMENT.intensity >> 2;
uint32_t counter = (now * SEGMENT.speed) >> 9; uint32_t counter = (now * SEGMENT.speed) >> 9;
for(uint16_t i = 0; i < SEGLEN; i++) { for(uint16_t i = 0; i < SEGLEN; i++) {
uint8_t s = 0; uint8_t s = 0;
uint8_t t = 0;
uint8_t a = i*x_scale - counter; uint8_t a = i*x_scale - counter;
uint8_t b = (SEGLEN-1-i)*x_scale - counter;
if (saw) { if (saw) {
if (a < 16) if (a < 16)
{ {
@ -442,12 +444,24 @@ uint16_t WS2812FX::running_base(bool saw) {
} }
} }
s = sin8(a); s = sin8(a);
setPixelColor(i, color_blend(color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), SEGCOLOR(1), s)); t = sin8(b);
uint32_t ca = color_blend(color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), SEGCOLOR(1), s);
uint32_t cb = color_blend(color_from_palette(i, true, PALETTE_SOLID_WRAP, 2), SEGCOLOR(1), t);
uint32_t cl = dual ? color_blend(ca, cb, 127) : ca;
setPixelColor(i, cl);
} }
return FRAMETIME; return FRAMETIME;
} }
/*
* Running lights in opposite directions.
*/
uint16_t WS2812FX::mode_running_dual(void) {
return running_base(false, true);
}
/* /*
* Running lights effect with smooth sine transition. * Running lights effect with smooth sine transition.
*/ */

View File

@ -91,7 +91,7 @@
#define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE ) #define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE )
#define IS_SELECTED ((SEGMENT.options & SELECTED) == SELECTED ) #define IS_SELECTED ((SEGMENT.options & SELECTED) == SELECTED )
#define MODE_COUNT 101 #define MODE_COUNT 102
#define FX_MODE_STATIC 0 #define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1 #define FX_MODE_BLINK 1
@ -194,6 +194,7 @@
#define FX_MODE_PERCENT 98 #define FX_MODE_PERCENT 98
#define FX_MODE_RIPPLE_RAINBOW 99 #define FX_MODE_RIPPLE_RAINBOW 99
#define FX_MODE_HEARTBEAT 100 #define FX_MODE_HEARTBEAT 100
#define FX_MODE_RUNNING_DUAL 101
class WS2812FX { class WS2812FX {
typedef uint16_t (WS2812FX::*mode_ptr)(void); typedef uint16_t (WS2812FX::*mode_ptr)(void);
@ -383,6 +384,7 @@ class WS2812FX {
_mode[FX_MODE_PERCENT] = &WS2812FX::mode_percent; _mode[FX_MODE_PERCENT] = &WS2812FX::mode_percent;
_mode[FX_MODE_RIPPLE_RAINBOW] = &WS2812FX::mode_ripple_rainbow; _mode[FX_MODE_RIPPLE_RAINBOW] = &WS2812FX::mode_ripple_rainbow;
_mode[FX_MODE_HEARTBEAT] = &WS2812FX::mode_heartbeat; _mode[FX_MODE_HEARTBEAT] = &WS2812FX::mode_heartbeat;
_mode[FX_MODE_RUNNING_DUAL] = &WS2812FX::mode_running_dual;
_brightness = DEFAULT_BRIGHTNESS; _brightness = DEFAULT_BRIGHTNESS;
currentPalette = CRGBPalette16(CRGB::Black); currentPalette = CRGBPalette16(CRGB::Black);
@ -568,7 +570,8 @@ class WS2812FX {
mode_plasma(void), mode_plasma(void),
mode_percent(void), mode_percent(void),
mode_ripple_rainbow(void), mode_ripple_rainbow(void),
mode_heartbeat(void); mode_heartbeat(void),
mode_running_dual(void);
private: private:
@ -607,7 +610,7 @@ class WS2812FX {
color_wipe(bool, bool), color_wipe(bool, bool),
scan(bool), scan(bool),
theater_chase(uint32_t, uint32_t, bool), theater_chase(uint32_t, uint32_t, bool),
running_base(bool), running_base(bool,bool),
larson_scanner(bool), larson_scanner(bool),
sinelon_base(bool,bool), sinelon_base(bool,bool),
dissolve(uint32_t), dissolve(uint32_t),
@ -650,7 +653,7 @@ const char JSON_mode_names[] PROGMEM = R"=====([
"Noise 1","Noise 2","Noise 3","Noise 4","Colortwinkles","Lake","Meteor","Meteor Smooth","Railway","Ripple", "Noise 1","Noise 2","Noise 3","Noise 4","Colortwinkles","Lake","Meteor","Meteor Smooth","Railway","Ripple",
"Twinklefox","Twinklecat","Halloween Eyes","Solid Pattern","Solid Pattern Tri","Spots","Spots Fade","Glitter","Candle","Fireworks Starburst", "Twinklefox","Twinklecat","Halloween Eyes","Solid Pattern","Solid Pattern Tri","Spots","Spots Fade","Glitter","Candle","Fireworks Starburst",
"Fireworks 1D","Bouncing Balls","Sinelon","Sinelon Dual","Sinelon Rainbow","Popcorn","Drip","Plasma","Percent","Ripple Rainbow", "Fireworks 1D","Bouncing Balls","Sinelon","Sinelon Dual","Sinelon Rainbow","Popcorn","Drip","Plasma","Percent","Ripple Rainbow",
"Heartbeat" "Heartbeat","Running Dual"
])====="; ])=====";