From 13f18492ade01a92c9e3b26db7b47c14f02eb421 Mon Sep 17 00:00:00 2001 From: Jeff Rescignano Date: Mon, 12 Oct 2020 14:13:13 -0400 Subject: [PATCH] Disable onboard LED when LEDs are not in use (#1245) * Disable onboard LED when LEDs are not in use * Remove unused variable * Only disable onboard LED if LEDPIN == LED_BUILTIN * Change LEDPIN to LED_BUILTIN --- wled00/FX.h | 1 + wled00/FX_fcn.cpp | 12 ++++++++++++ wled00/button.cpp | 14 ++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index e3c170f7..622bda22 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -650,6 +650,7 @@ class WS2812FX { void handle_palette(void); bool + shouldStartBus = false, _useRgbw = false, _skipFirstMode, _triggered; diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 56fdb98a..ad459aba 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -396,6 +396,18 @@ void WS2812FX::setBrightness(uint8_t b) { { _segments[i].setOption(SEG_OPTION_FREEZE, false); } + #if LEDPIN == LED_BUILTIN + if (!shouldStartBus) + shouldStartBus = true; + #endif + } else { + #if LEDPIN == LED_BUILTIN + if (shouldStartBus) { + shouldStartBus = false; + const uint8_t ty = _useRgbw ? 2 : 1; + bus->Begin((NeoPixelType)ty, _lengthRaw); + } + #endif } if (SEGENV.next_time > millis() + 22 && millis() - _lastShow > MIN_SHOW_DELAY) show();//apply brightness change immediately if no refresh soon } diff --git a/wled00/button.cpp b/wled00/button.cpp index 3c7b7f14..280a571a 100644 --- a/wled00/button.cpp +++ b/wled00/button.cpp @@ -87,7 +87,7 @@ void handleIO() { lastOnTime = millis(); if (offMode) - { + { #if RLYPIN >= 0 digitalWrite(RLYPIN, RLYMDE); #endif @@ -95,9 +95,15 @@ void handleIO() } } else if (millis() - lastOnTime > 600) { - #if RLYPIN >= 0 - if (!offMode) digitalWrite(RLYPIN, !RLYMDE); - #endif + if (!offMode) { + #if LEDPIN == LED_BUILTIN + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); + #endif + #if RLYPIN >= 0 + digitalWrite(RLYPIN, !RLYMDE); + #endif + } offMode = true; }