From 34c9c5a9b1314f4d419424b4df09d1c18ded12d5 Mon Sep 17 00:00:00 2001 From: guardmedia Date: Tue, 15 Dec 2020 07:35:50 -0500 Subject: [PATCH] Adding palette blends effect (#1491) * Adding palette blends effect * Fixes for blends effect * Improved blend effect intesity and speed control * Simplify Blends timing Co-authored-by: Tyler Walters Co-authored-by: cschwinne --- wled00/FX.cpp | 20 ++++++++++++++++++++ wled00/FX.h | 9 ++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index d95cc351..b3308a9a 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -3733,3 +3733,23 @@ uint16_t WS2812FX::mode_washing_machine(void) { return FRAMETIME; } + +/* + Blends random colors across palette + Modified, originally by Mark Kriegsman https://gist.github.com/kriegsman/1f7ccbbfa492a73c015e +*/ +uint16_t WS2812FX::mode_blends(void) { + uint16_t dataSize = sizeof(uint32_t) * SEGLEN; + if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed + uint32_t* pixels = reinterpret_cast(SEGENV.data); + uint8_t blendSpeed = map(SEGMENT.intensity, 0, UINT8_MAX, 10, 128); + uint8_t shift = (now * ((SEGMENT.speed >> 3) +1)) >> 8; + + for (int i = 0; i < SEGLEN; i++) { + pixels[i] = color_blend(pixels[i], color_from_palette(shift + quadwave8((i + 1) * 16), false, PALETTE_SOLID_WRAP, 255), blendSpeed); + setPixelColor(i, pixels[i]); + shift += 3; + } + + return FRAMETIME; +} \ No newline at end of file diff --git a/wled00/FX.h b/wled00/FX.h index 2255b674..a33b992d 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -116,7 +116,7 @@ #define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE ) #define IS_SELECTED ((SEGMENT.options & SELECTED ) == SELECTED ) -#define MODE_COUNT 115 +#define MODE_COUNT 116 #define FX_MODE_STATIC 0 #define FX_MODE_BLINK 1 @@ -233,6 +233,7 @@ #define FX_MODE_DANCING_SHADOWS 112 #define FX_MODE_WASHING_MACHINE 113 #define FX_MODE_CANDY_CANE 114 +#define FX_MODE_BLENDS 115 class WS2812FX { typedef uint16_t (WS2812FX::*mode_ptr)(void); @@ -461,6 +462,7 @@ class WS2812FX { _mode[FX_MODE_DANCING_SHADOWS] = &WS2812FX::mode_dancing_shadows; _mode[FX_MODE_WASHING_MACHINE] = &WS2812FX::mode_washing_machine; _mode[FX_MODE_CANDY_CANE] = &WS2812FX::mode_candy_cane; + _mode[FX_MODE_BLENDS] = &WS2812FX::mode_blends; _brightness = DEFAULT_BRIGHTNESS; currentPalette = CRGBPalette16(CRGB::Black); @@ -670,7 +672,8 @@ class WS2812FX { mode_chunchun(void), mode_dancing_shadows(void), mode_washing_machine(void), - mode_candy_cane(void); + mode_candy_cane(void), + mode_blends(void); private: NeoPixelWrapper *bus; @@ -758,7 +761,7 @@ const char JSON_mode_names[] PROGMEM = R"=====([ "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", "Heartbeat","Pacifica","Candle Multi", "Solid Glitter","Sunrise","Phased","Twinkleup","Noise Pal", "Sine","Phased Noise", -"Flow","Chunchun","Dancing Shadows","Washing Machine","Candy Cane" +"Flow","Chunchun","Dancing Shadows","Washing Machine","Candy Cane","Blends" ])=====";