From bec745d095adc87472a0aff979f0ca09cf8158ae Mon Sep 17 00:00:00 2001 From: cschwinne Date: Sun, 16 Dec 2018 20:38:00 +0100 Subject: [PATCH] Improved colortwinkles on longer strips Added offMode --- wled00/WS2812FX.cpp | 23 +++++++++++++---------- wled00/wled00.ino | 18 ++++++++++++++++-- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/wled00/WS2812FX.cpp b/wled00/WS2812FX.cpp index 60b90b9b..1ec2d251 100644 --- a/wled00/WS2812FX.cpp +++ b/wled00/WS2812FX.cpp @@ -2582,16 +2582,19 @@ uint16_t WS2812FX::mode_colortwinkle() setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue); } } - - if( random8() <= SEGMENT.intensity ) { - for (uint8_t times = 0; times < 5; times++) //attempt to spawn a new pixel 5 times - { - int i = SEGMENT.start + random16(SEGMENT_LENGTH); - if(getPixelColor(i) == 0) { - fastled_col = ColorFromPalette(currentPalette, random8(), 64, NOBLEND); - _locked[i] = true; - setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue); - return 20; //only spawn 1 new pixel per frame + + for (uint16_t j = 0; j <= SEGMENT_LENGTH / 50; j++) + { + if ( random8() <= SEGMENT.intensity ) { + for (uint8_t times = 0; times < 5; times++) //attempt to spawn a new pixel 5 times + { + int i = SEGMENT.start + random16(SEGMENT_LENGTH); + if(getPixelColor(i) == 0) { + fastled_col = ColorFromPalette(currentPalette, random8(), 64, NOBLEND); + _locked[i] = true; + setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue); + break; //only spawn 1 new pixel per frame per 50 LEDs + } } } } diff --git a/wled00/wled00.ino b/wled00/wled00.ino index b742fb53..37bfec49 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -74,7 +74,7 @@ //version code in format yymmddb (b = daily build) -#define VERSION 1812052 +#define VERSION 1812141 char versionString[] = "0.8.2"; @@ -271,6 +271,8 @@ unsigned long nightlightStartTime; byte briNlT = 0; //current nightlight brightness //brightness +bool offMode = false; +unsigned long lastOnTime = 0; byte bri = briS; byte briOld = 0; byte briT = 0; @@ -528,7 +530,19 @@ void loop() { handleHue(); handleBlynk(); } - if (briT) strip.service(); //do not update strip if off, prevents flicker on ESP32 + if (briT) lastOnTime = millis(); + if (millis() - lastOnTime < 600) + { + offMode = false; + strip.service(); + } else if (!offMode) + { + /*#if LEDPIN == 2 //turn off onboard LED + pinMode(2, OUTPUT); + digitalWrite(2, HIGH); + #endif*/ + offMode = true; + } } //DEBUG serial logging