#include <TaskScheduler.h>
// LED_BUILTIN 13
#if defined( ARDUINO_ARCH_ESP32 )
#define LED_BUILTIN 23 // esp32 dev2 kit does not have LED
#endif
// Scheduler
Scheduler schedule;
/*
*/
#define PERIOD1 0
#define PERIOD2 0
#define DURATION1 1000
#define DURATION2 100
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
int ledState = LOW;
// Callback
void blink1CB();
void blink2CB();
// Tasks That runs both at the same time with no delays
Task tBlink1 ( PERIOD1 , TASK_FOREVER, &blink1CB);
Task tBlink2 ( PERIOD2 , TASK_FOREVER, &blink2CB);
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
schedule.init();
schedule.addTask(tBlink1);
schedule.addTask(tBlink2);
tBlink1.enable();
tBlink2.enable();
}
void loop() {
schedule.execute();
}
void blink1CB() {
unsigned long currentMillis1 = millis();
if(currentMillis1 - previousMillis1 > DURATION1) {
previousMillis1 = currentMillis1;
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
digitalWrite(13, ledState);
}
}
void blink2CB() {
unsigned long currentMillis2 = millis();
if(currentMillis2 - previousMillis2 > DURATION2) {
previousMillis2 = currentMillis2;
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
digitalWrite(12, ledState);
}
}