Updates to LED control code

Don't call digitaWrite on each setLED call
This commit is contained in:
Oleg Kalachev 2024-11-04 16:28:43 +03:00
parent e7445599cc
commit cd5f6721dc

View File

@ -1,7 +1,7 @@
// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com> // Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
// Repository: https://github.com/okalachev/flix // Repository: https://github.com/okalachev/flix
// Main LED control // Board's LED control
#define BLINK_PERIOD 500000 #define BLINK_PERIOD 500000
@ -14,7 +14,12 @@ void setupLED() {
} }
void setLED(bool on) { 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); digitalWrite(LED_BUILTIN, on ? HIGH : LOW);
state = on;
} }
void blinkLED() { void blinkLED() {