flix/flix/led.ino
Oleg Kalachev cd5f6721dc Updates to LED control code
Don't call digitaWrite on each setLED call
2024-11-04 16:28:43 +03:00

28 lines
542 B
C++

// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
// Repository: https://github.com/okalachev/flix
// Board's LED control
#define BLINK_PERIOD 500000
#ifndef LED_BUILTIN
#define LED_BUILTIN 2 // for ESP32 Dev Module
#endif
void setupLED() {
pinMode(LED_BUILTIN, OUTPUT);
}
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() {
setLED(micros() / BLINK_PERIOD % 2);
}