Skip to content

Commit

Permalink
Percent Effect from both ends of the strip (Aircoookie#660)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Def3nder authored Feb 6, 2020
1 parent ca1f25e commit 06a5c1a
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 06a5c1a

Please sign in to comment.