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.
This commit is contained in:
Def3nder 2020-02-06 01:36:01 +01:00 committed by GitHub
parent ca1f25ecf6
commit 06a5c1a798
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {