From cd5f6721dccb4008e240e24ff410399ae9b3d1db Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Mon, 4 Nov 2024 16:28:43 +0300 Subject: [PATCH] Updates to LED control code Don't call digitaWrite on each setLED call --- flix/led.ino | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/flix/led.ino b/flix/led.ino index f06a926..65b04a5 100644 --- a/flix/led.ino +++ b/flix/led.ino @@ -1,7 +1,7 @@ // Copyright (c) 2023 Oleg Kalachev // Repository: https://github.com/okalachev/flix -// Main LED control +// Board's LED control #define BLINK_PERIOD 500000 @@ -14,7 +14,12 @@ void setupLED() { } void setLED(bool on) { + static bool state = false; + if (on == state) { + return; // don't call digitalWrite if the state is the same + } digitalWrite(LED_BUILTIN, on ? HIGH : LOW); + state = on; } void blinkLED() {