From a91d993c6dc71c060246ebf31bbefd700357b1da Mon Sep 17 00:00:00 2001 From: Def3nder Date: Tue, 22 Dec 2020 16:26:19 +0100 Subject: [PATCH] Dynamic fade effect (#1550) * New Effect "TV Simulator" based on "Fake TV Light for Engineers" by Phillip Burgess https://learn.adafruit.com/fake-tv-light-for-engineers/arduino-sketch * removed some not-used functions ...from my 1st attempt with "Phoney TV" - but this one did not look good. * Dynamic Effect extended with a "smooth" variant ...to close #1114 / the "Dynamice fade effect" in the projects section Co-authored-by: Aircoookie --- wled00/FX.cpp | 31 ++++++++++++++++++++++++++----- wled00/FX.h | 11 ++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 26400379..31f7a8f0 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -234,9 +234,9 @@ uint16_t WS2812FX::mode_random_color(void) { /* * Lights every LED in a random color. Changes all LED at the same time -// * to new random colors. + * to new random colors. */ -uint16_t WS2812FX::mode_dynamic(void) { +uint16_t WS2812FX::dynamic(boolean smooth=false) { if (!SEGENV.allocateData(SEGLEN)) return mode_static(); //allocation failed if(SEGENV.call == 0) { @@ -253,12 +253,31 @@ uint16_t WS2812FX::mode_dynamic(void) { SEGENV.step = it; } - for (uint16_t i = 0; i < SEGLEN; i++) { - setPixelColor(i, color_wheel(SEGENV.data[i])); - } + if (smooth) { + for (uint16_t i = 0; i < SEGLEN; i++) { + blendPixelColor(i, color_wheel(SEGENV.data[i]),16); + } + } else { + for (uint16_t i = 0; i < SEGLEN; i++) { + setPixelColor(i, color_wheel(SEGENV.data[i])); + } + } return FRAMETIME; } +/* + * Original effect "Dynamic" + */ +uint16_t WS2812FX::mode_dynamic(void) { + return dynamic(false); +} + +/* + * effect "Dynamic" with smoth color-fading + */ +uint16_t WS2812FX::mode_dynamic_smooth(void) { + return dynamic(true); + } /* * Does the "standby-breathing" of well known i-Devices. @@ -3755,6 +3774,7 @@ uint16_t WS2812FX::mode_blends(void) { return FRAMETIME; } +#ifndef WLED_DISABLE_FX_HIGH_FLASH_USE typedef struct TvSim { uint32_t totalTime = 0; uint32_t fadeTime = 0; @@ -3767,6 +3787,7 @@ typedef struct TvSim { } tvSim; #define numTVPixels (sizeof(tv_colors) / 2) // 2 bytes per Pixel (5/6/5) +#endif /* TV Simulator diff --git a/wled00/FX.h b/wled00/FX.h index bf8df390..f368e567 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -119,7 +119,8 @@ #define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE ) #define IS_SELECTED ((SEGMENT.options & SELECTED ) == SELECTED ) -#define MODE_COUNT 117 + +#define MODE_COUNT 118 #define FX_MODE_STATIC 0 #define FX_MODE_BLINK 1 @@ -238,6 +239,7 @@ #define FX_MODE_CANDY_CANE 114 #define FX_MODE_BLENDS 115 #define FX_MODE_TV_SIMULATOR 116 +#define FX_MODE_DYNAMIC_SMOOTH 117 class WS2812FX { typedef uint16_t (WS2812FX::*mode_ptr)(void); @@ -468,6 +470,7 @@ class WS2812FX { _mode[FX_MODE_CANDY_CANE] = &WS2812FX::mode_candy_cane; _mode[FX_MODE_BLENDS] = &WS2812FX::mode_blends; _mode[FX_MODE_TV_SIMULATOR] = &WS2812FX::mode_tv_simulator; + _mode[FX_MODE_DYNAMIC_SMOOTH] = &WS2812FX::mode_dynamic_smooth; _brightness = DEFAULT_BRIGHTNESS; currentPalette = CRGBPalette16(CRGB::Black); @@ -679,7 +682,8 @@ class WS2812FX { mode_washing_machine(void), mode_candy_cane(void), mode_blends(void), - mode_tv_simulator(void); + mode_tv_simulator(void), + mode_dynamic_smooth(void); private: NeoPixelWrapper *bus; @@ -712,6 +716,7 @@ class WS2812FX { blink(uint32_t, uint32_t, bool strobe, bool), candle(bool), color_wipe(bool, bool), + dynamic(bool), scan(bool), theater_chase(uint32_t, uint32_t, bool), running_base(bool), @@ -767,7 +772,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","Blends","TV Simulator" +"Flow","Chunchun","Dancing Shadows","Washing Machine","Candy Cane","Blends","TV Simulator","Dynamic Smooth" ])=====";