From 06a5c1a798ea668f8794c2a92aac6ef6e9ccebd5 Mon Sep 17 00:00:00 2001 From: Def3nder <33399267+Def3nder@users.noreply.github.com> Date: Thu, 6 Feb 2020 01:36:01 +0100 Subject: [PATCH] Percent Effect from both ends of the strip (#660) from 0 to 100 the strip will get color(0) starting at the ESP, from 200 to 100 to strip will do it the other way around. So, when using this effect for the staircase usermod, a person entering area near the ESP would set an intensity starting with 1 and getting bigger and leaving on the other side would need to further increase the intensity until 200. then the strip has color(1) again. --- wled00/FX.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index bc488b987..a2f3d27a8 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -3013,21 +3013,34 @@ uint16_t WS2812FX::mode_plasma(void) { */ uint16_t WS2812FX::mode_percent(void) { - uint8_t percent = max(0, min(100, SEGMENT.intensity)); - uint16_t active_leds = SEGLEN * percent / 100.0; + uint8_t percent = max(0, min(200, SEGMENT.intensity)); + uint16_t active_leds = (percent < 100) ? SEGLEN * percent / 100.0 + : SEGLEN * (200 - percent) / 100.0; if (SEGENV.call == 0) SEGENV.step = 0; uint8_t size = (1 + ((SEGMENT.speed * SEGLEN) >> 11)) & 0xFF ; - for (uint16_t i = 0; i < SEGLEN; i++) { - if (i < SEGENV.step) { - setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); - } - else { - setPixelColor(i, SEGCOLOR(1)); - } - } - if(active_leds > SEGENV.step) { + if (percent < 100) { + for (uint16_t i = 0; i < SEGLEN; i++) { + if (i < SEGENV.step) { + setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); + } + else { + setPixelColor(i, SEGCOLOR(1)); + } + } + } else { + for (uint16_t i = 0; i < SEGLEN; i++) { + if (i < (SEGLEN - SEGENV.step)) { + setPixelColor(i, SEGCOLOR(1)); + } + else { + setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); + } + } + } + + if(active_leds > SEGENV.step) { // smooth transition to the target value SEGENV.step += size; if (SEGENV.step > active_leds) SEGENV.step = active_leds; } else if (active_leds < SEGENV.step) {