From 2b0a38d25d517734fa7cfa37fb08b2dbcb8afdc9 Mon Sep 17 00:00:00 2001 From: Def3nder <33399267+Def3nder@users.noreply.github.com> Date: Tue, 28 Jan 2020 13:47:18 +0100 Subject: [PATCH] Percent Effect with speed-slider (#637) --- wled00/FX.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index c3b8ed09..5c24efdb 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -2985,23 +2985,26 @@ uint16_t WS2812FX::mode_plasma(void) { uint16_t WS2812FX::mode_percent(void) { uint8_t percent = max(0, min(100, SEGMENT.intensity)); - - float active_float = SEGLEN * percent / 100.0; - uint16_t active_leds = active_float; - uint16_t active_part = (active_float - active_leds) * 255; - CRGB color; - - for (uint16_t i = 0; i < SEGLEN; i++) { - if (i < active_leds) { + uint16_t active_leds = SEGLEN * 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 if (i == active_leds) { - setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0, active_part)); - } else { setPixelColor(i, SEGCOLOR(1)); } - } + } + if(active_leds > SEGENV.step) { + SEGENV.step += size; + if (SEGENV.step > active_leds) SEGENV.step = active_leds; + } else if (active_leds < SEGENV.step) { + SEGENV.step -= size; + if (SEGENV.step < active_leds) SEGENV.step = active_leds; + } - return FRAMETIME; + return FRAMETIME; } \ No newline at end of file