From cf31ec30a0ecd55338aea699c8a330eeb612c6d2 Mon Sep 17 00:00:00 2001 From: lorinszkymark Date: Sat, 7 Dec 2024 15:04:14 +0100 Subject: [PATCH 1/3] Added wipe in and wipe out effects --- wled00/FX.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++ wled00/FX.h | 7 +++- 2 files changed, 118 insertions(+), 1 deletion(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index cb8813c930..4cbca8aefe 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -6466,6 +6466,113 @@ uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline. static const char _data_FX_MODE_MATRIPIX[] PROGMEM = "Matripix@!,Brightness;!,!;!;1v;ix=64,m12=2,si=1"; //,rev=1,mi=1,rY=1,mY=1 Circle, WeWillRockYou, reverseX +////////////////////// +// * WIPE OUT // +////////////////////// +uint16_t mode_wipe_out(void) { + if (SEGLEN == 1) return mode_static(); + + uint16_t duration = 1000 - (SEGMENT.speed * 4); // Adjust speed (1-255) to duration (1000ms to 20ms) + uint16_t stepDuration = duration / SEGLEN; + uint32_t currentTime = millis(); + + if (SEGENV.call == 0) { + SEGENV.aux0 = currentTime; // Start time + SEGENV.aux1 = 0; // Current LED + } + + if (currentTime - SEGENV.aux0 > stepDuration) { + SEGENV.aux0 = currentTime; + if (SEGENV.aux1 < SEGLEN) { + SEGMENT.setPixelColor(SEGENV.aux1, BLACK); + SEGENV.aux1++; + } else { + // All LEDs are off, reset + SEGENV.aux1 = 0; + strip.setBrightness(0); + return 65535; + } + } + + return FRAMETIME; +} + +// Add the effect details to the list +static const char _data_FX_MODE_WIPE_OUT[] PROGMEM = + "Wipe Out@!,Wipe Speed;1,!;!;1v;ix=64"; + + +////////////////////// +// * WIPE IN // +////////////////////// +uint16_t mode_wipe_in(uint16_t segPerLoop) { + if (SEGLEN == 1) return mode_static(); + + uint16_t duration = 1000 - (SEGMENT.speed * 4); // Adjust speed (1-255) to duration (1000ms to 20ms) + uint16_t stepDuration = duration / SEGLEN; + uint32_t currentTime = millis(); + + if (SEGENV.call == 0) { + SEGENV.aux0 = currentTime; // Start time + SEGENV.aux1 = SEGLEN - 1; // Current LED + SEGMENT.fill(BLACK); // Start with all LEDs off + } + + if (currentTime - SEGENV.aux0 > stepDuration) { + SEGENV.aux0 = currentTime; + if (SEGENV.aux1 >= 0 && SEGENV.aux1 < SEGLEN) { + uint32_t color = SEGCOLOR(0); // Use primary color + if (SEGCOLOR(1) != BLACK) { + color = color_blend(color, SEGCOLOR(1), SEGMENT.intensity); // Blend with secondary color if set + } + for (int i = 1; i < segPerLoop && SEGENV.aux1 >= 0 && SEGENV.aux1 < SEGLEN; i++) { + SEGMENT.setPixelColor(SEGENV.aux1, color); + SEGENV.aux1--; + } + } else { + // All LEDs are on, reset + SEGENV.aux1 = SEGLEN - 1; + return 65535; + } + } + + return FRAMETIME; +} + +uint16_t mode_wipe_in_normal(void) { + return mode_wipe_in(1); +} + +// Add the effect details to the list +static const char _data_FX_MODE_WIPE_IN_NORMAL[] PROGMEM = + "Wipe In@!,Wipe Speed;1,!;!;1v;ix=64"; + + +uint16_t mode_wipe_in_fast(void) { + return mode_wipe_in(2); +} + +// Add the effect details to the list +static const char _data_FX_MODE_WIPE_IN_FAST[] PROGMEM = + "Wipe In fast@!,Wipe Speed;1,!;!;1v;ix=64"; + + +uint16_t mode_wipe_in_faster(void) { + return mode_wipe_in(3); +} + +// Add the effect details to the list +static const char _data_FX_MODE_WIPE_IN_FASTER[] PROGMEM = + "Wipe In faster@!,Wipe Speed;1,!;!;1v;ix=64"; + +uint16_t mode_wipe_in_very_fast(void) { + return mode_wipe_in(4); +} + +// Add the effect details to the list +static const char _data_FX_MODE_WIPE_IN_VERY_FAST[] PROGMEM = + "Wipe In Very Fast@!,Wipe Speed;1,!;!;1v;ix=64"; + ////////////////////// // * MIDNOISE // ////////////////////// @@ -7819,6 +7926,11 @@ void WS2812FX::setupEffectData() { addEffect(FX_MODE_PIXELWAVE, &mode_pixelwave, _data_FX_MODE_PIXELWAVE); addEffect(FX_MODE_JUGGLES, &mode_juggles, _data_FX_MODE_JUGGLES); addEffect(FX_MODE_MATRIPIX, &mode_matripix, _data_FX_MODE_MATRIPIX); + addEffect(FX_MODE_WIPE_OUT, &mode_wipe_out, _data_FX_MODE_WIPE_OUT); + addEffect(FX_MODE_WIPE_IN, &mode_wipe_in_normal, _data_FX_MODE_WIPE_IN_NORMAL); + addEffect(FX_MODE_WIPE_IN_FAST, &mode_wipe_in_fast, _data_FX_MODE_WIPE_IN_FAST); + addEffect(FX_MODE_WIPE_IN_FASTER, &mode_wipe_in_faster, _data_FX_MODE_WIPE_IN_FASTER); + addEffect(FX_MODE_WIPE_IN_VERY_FAST, &mode_wipe_in_faster, _data_FX_MODE_WIPE_IN_FASTER); addEffect(FX_MODE_GRAVIMETER, &mode_gravimeter, _data_FX_MODE_GRAVIMETER); addEffect(FX_MODE_PLASMOID, &mode_plasmoid, _data_FX_MODE_PLASMOID); addEffect(FX_MODE_PUDDLES, &mode_puddles, _data_FX_MODE_PUDDLES); diff --git a/wled00/FX.h b/wled00/FX.h index 167ed8f0f0..9665389922 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -314,8 +314,13 @@ #define FX_MODE_WAVESINS 184 #define FX_MODE_ROCKTAVES 185 #define FX_MODE_2DAKEMI 186 +#define FX_MODE_WIPE_OUT 187 +#define FX_MODE_WIPE_IN 188 +#define FX_MODE_WIPE_IN_FAST 189 +#define FX_MODE_WIPE_IN_FASTER 190 +#define FX_MODE_WIPE_IN_VERY_FAST 191 -#define MODE_COUNT 187 +#define MODE_COUNT 191 typedef enum mapping1D2D { M12_Pixels = 0, From 5cdd9aa5521904f45881c6f26b219afe24844458 Mon Sep 17 00:00:00 2001 From: lorinszkymark Date: Mon, 30 Dec 2024 10:11:19 +0100 Subject: [PATCH 2/3] fixing bug --- wled00/FX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 4cbca8aefe..4e9912eb49 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -6525,7 +6525,7 @@ uint16_t mode_wipe_in(uint16_t segPerLoop) { if (SEGCOLOR(1) != BLACK) { color = color_blend(color, SEGCOLOR(1), SEGMENT.intensity); // Blend with secondary color if set } - for (int i = 1; i < segPerLoop && SEGENV.aux1 >= 0 && SEGENV.aux1 < SEGLEN; i++) { + for (int i = 0; i < segPerLoop && SEGENV.aux1 >= 0 && SEGENV.aux1 < SEGLEN; i++) { SEGMENT.setPixelColor(SEGENV.aux1, color); SEGENV.aux1--; } From 74f6618ea036f4c8e38456810939ecb6c737a3a6 Mon Sep 17 00:00:00 2001 From: lorinszkymark Date: Mon, 30 Dec 2024 23:10:22 +0100 Subject: [PATCH 3/3] code cleaning --- wled00/FX.cpp | 68 +++++++++++++++++---------------------------------- wled00/FX.h | 5 +--- 2 files changed, 24 insertions(+), 49 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 446287dd93..9dd89d8277 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -6598,9 +6598,14 @@ static const char _data_FX_MODE_MATRIPIX[] PROGMEM = "Matripix@!,Brightness;!,!; uint16_t mode_wipe_out(void) { if (SEGLEN == 1) return mode_static(); - uint16_t duration = 1000 - (SEGMENT.speed * 4); // Adjust speed (1-255) to duration (1000ms to 20ms) + uint16_t duration = 4100 - (SEGMENT.speed * 16); // Adjust speed (1-255) to duration (1000ms to 20ms) uint16_t stepDuration = duration / SEGLEN; uint32_t currentTime = millis(); + uint16_t segPerLoop = floor(SEGMENT.intensity / 64); + + if(segPerLoop < 1){ + segPerLoop = 1; + } if (SEGENV.call == 0) { SEGENV.aux0 = currentTime; // Start time @@ -6610,8 +6615,10 @@ uint16_t mode_wipe_out(void) { if (currentTime - SEGENV.aux0 > stepDuration) { SEGENV.aux0 = currentTime; if (SEGENV.aux1 < SEGLEN) { - SEGMENT.setPixelColor(SEGENV.aux1, BLACK); - SEGENV.aux1++; + for (int i = 0; i < segPerLoop && SEGENV.aux1 >= 0 && SEGENV.aux1 < SEGLEN; i++) { + SEGMENT.setPixelColor(SEGENV.aux1, BLACK); + SEGENV.aux1++; + } } else { // All LEDs are off, reset SEGENV.aux1 = 0; @@ -6625,18 +6632,23 @@ uint16_t mode_wipe_out(void) { // Add the effect details to the list static const char _data_FX_MODE_WIPE_OUT[] PROGMEM = - "Wipe Out@!,Wipe Speed;1,!;!;1v;ix=64"; + "Wipe Out@!,Boost speed;!,!;!;ix=64"; ////////////////////// // * WIPE IN // ////////////////////// -uint16_t mode_wipe_in(uint16_t segPerLoop) { +uint16_t mode_wipe_in(void) { if (SEGLEN == 1) return mode_static(); - uint16_t duration = 1000 - (SEGMENT.speed * 4); // Adjust speed (1-255) to duration (1000ms to 20ms) + uint16_t duration = 4100 - (SEGMENT.speed * 16); // Adjust speed (1-255) to duration (1000ms to 20ms) uint16_t stepDuration = duration / SEGLEN; uint32_t currentTime = millis(); + uint16_t segPerLoop = floor(SEGMENT.intensity / 64); + + if(segPerLoop < 1){ + segPerLoop = 1; + } if (SEGENV.call == 0) { SEGENV.aux0 = currentTime; // Start time @@ -6644,7 +6656,8 @@ uint16_t mode_wipe_in(uint16_t segPerLoop) { SEGMENT.fill(BLACK); // Start with all LEDs off } - if (currentTime - SEGENV.aux0 > stepDuration) { + uint16_t timediff = currentTime - SEGENV.aux0; + if (timediff > stepDuration) { SEGENV.aux0 = currentTime; if (SEGENV.aux1 >= 0 && SEGENV.aux1 < SEGLEN) { uint32_t color = SEGCOLOR(0); // Use primary color @@ -6661,43 +6674,11 @@ uint16_t mode_wipe_in(uint16_t segPerLoop) { return 65535; } } - return FRAMETIME; } -uint16_t mode_wipe_in_normal(void) { - return mode_wipe_in(1); -} - -// Add the effect details to the list -static const char _data_FX_MODE_WIPE_IN_NORMAL[] PROGMEM = - "Wipe In@!,Wipe Speed;1,!;!;1v;ix=64"; - - -uint16_t mode_wipe_in_fast(void) { - return mode_wipe_in(2); -} - -// Add the effect details to the list -static const char _data_FX_MODE_WIPE_IN_FAST[] PROGMEM = - "Wipe In fast@!,Wipe Speed;1,!;!;1v;ix=64"; - - -uint16_t mode_wipe_in_faster(void) { - return mode_wipe_in(3); -} - -// Add the effect details to the list -static const char _data_FX_MODE_WIPE_IN_FASTER[] PROGMEM = - "Wipe In faster@!,Wipe Speed;1,!;!;1v;ix=64"; - -uint16_t mode_wipe_in_very_fast(void) { - return mode_wipe_in(4); -} - -// Add the effect details to the list -static const char _data_FX_MODE_WIPE_IN_VERY_FAST[] PROGMEM = - "Wipe In Very Fast@!,Wipe Speed;1,!;!;1v;ix=64"; +static const char _data_FX_MODE_WIPE_IN[] PROGMEM = + "Wipe In@!,Boost speed;!,!;!"; ////////////////////// // * MIDNOISE // @@ -7916,10 +7897,7 @@ void WS2812FX::setupEffectData() { addEffect(FX_MODE_JUGGLES, &mode_juggles, _data_FX_MODE_JUGGLES); addEffect(FX_MODE_MATRIPIX, &mode_matripix, _data_FX_MODE_MATRIPIX); addEffect(FX_MODE_WIPE_OUT, &mode_wipe_out, _data_FX_MODE_WIPE_OUT); - addEffect(FX_MODE_WIPE_IN, &mode_wipe_in_normal, _data_FX_MODE_WIPE_IN_NORMAL); - addEffect(FX_MODE_WIPE_IN_FAST, &mode_wipe_in_fast, _data_FX_MODE_WIPE_IN_FAST); - addEffect(FX_MODE_WIPE_IN_FASTER, &mode_wipe_in_faster, _data_FX_MODE_WIPE_IN_FASTER); - addEffect(FX_MODE_WIPE_IN_VERY_FAST, &mode_wipe_in_faster, _data_FX_MODE_WIPE_IN_FASTER); + addEffect(FX_MODE_WIPE_IN, &mode_wipe_in, _data_FX_MODE_WIPE_IN); addEffect(FX_MODE_GRAVIMETER, &mode_gravimeter, _data_FX_MODE_GRAVIMETER); addEffect(FX_MODE_PLASMOID, &mode_plasmoid, _data_FX_MODE_PLASMOID); addEffect(FX_MODE_PUDDLES, &mode_puddles, _data_FX_MODE_PUDDLES); diff --git a/wled00/FX.h b/wled00/FX.h index 5d7500bf62..74483fc0b8 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -324,11 +324,8 @@ extern byte realtimeMode; // used in getMappedPixelIndex() #define FX_MODE_2DAKEMI 186 #define FX_MODE_WIPE_OUT 187 #define FX_MODE_WIPE_IN 188 -#define FX_MODE_WIPE_IN_FAST 189 -#define FX_MODE_WIPE_IN_FASTER 190 -#define FX_MODE_WIPE_IN_VERY_FAST 191 -#define MODE_COUNT 191 +#define MODE_COUNT 188 typedef enum mapping1D2D { M12_Pixels = 0,