Dependancies
Pre-requisites
Buy the components
ticker.ino
// https://github.com/esp8266/Arduino/blob/master/libraries/Ticker/examples/TickerBasic/TickerBasic.ino
#include <Ticker.h>
Ticker ticker;
int count = 0;
bool isLEDToggle = false; // some kind of status
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Serial.begin(115200);
Serial.println("Hello!");
ticker.attach(1, blink); // start the ticker
isLEDToggle = true;
}
void loop() {
if (count > 10) { // off the LED when not require
ticker.detach();
ledOFF();
isLEDToggle = false;
}
Serial.println(count);
count++;
delay(2000);
}
void blink() {
int state = digitalRead(LED_BUILTIN);
if (isLEDToggle) {
digitalWrite(LED_BUILTIN, !state);
}
}
void ledOFF() {
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("OFF LED");
}
.PHONY: lint compile upload clean
lint:
cpplint --extensions=ino --filter=-legal/copyright,-readability/todo *.ino
compile:
arduino-cli compile --fqbn esp8266com:esp8266:d1_mini .
upload: compile
arduino-cli upload -p /dev/cu.wchusbserial1410 --fqbn esp8266com:esp8266:d1_mini .
clean:
rm -f .*.bin
rm -f .*.elf
flash: lint compile upload clean
Blink the on-board LED without using the loop()
.