Skip to content

armgit / flix

Public Imported from GitHub
0

Making an ESP32-based quadcopter from scratch

Updates to LED control code Don't call digitaWrite on each setLED call

Oleg Kalachevcd5f6721dccb
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 <[email protected]>
// 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() {