SimpleLed is an Arduino library that controls the on, off, and blink functions of LEDs. It's a particularly simple project that aims to control LED blinking without using blocking delays.
You need to include SimpleLed.h in your project.
#include "SimpleLed.h"After initializing the LED pin, the LED will be set to the off state by default.
To turn on the LED when the pin output is high:
#define LED_PIN LED_BUILTIN
SimpleLed led(LED_PIN);Or:
#define LED_PIN LED_BUILTIN
SimpleLed led(LED_PIN, HIGH);To turn on the LED when the pin output is low:
#define LED_PIN LED_BUILTIN
SimpleLed led(LED_PIN, LOW); led.setState(SimpleLed::LedState::ON);Or:
led.setState(1);Or:
led.on(); led.setState(SimpleLed::LedState::OFF);Or:
led.setState(0);Or:
led.off();The LED switches state every 1s (on-1s->off-1s->on ->...) and you need to call update() in loop():
void setup() {
led.setState(SimpleLed::LedState::BLINK, 1000);
}
void loop() {
led.update();
}Or:
void setup() {
led.blink(1000);
}
void loop() {
led.update();
}