/*
An example of using scheduler's custom sleep callback method
An empty loop is executed for 10 seconds with a 10 ms. interval
The first time it is excuted with an empty sleep callback, and
the second time with a 1 ms delay in the custom callback
RESULTS:
Arduino Nano:
=================================
Testing empty sleep callback...
cEmptyCallback=1001
cEmptyTotal=423866
Testing 1 ms delayed sleep callback...
cDelayCallback=1001
cDelayTotal=10669
ESP8266 at 80MHz
=================================
Testing empty sleep callback...
cEmptyCallback=1001
cEmptyTotal=278101
Testing 1 ms delayed sleep callback...
cDelayCallback=1001
cDelayTotal=10493
ESP8266 at 160MHz
=================================
Testing empty sleep callback...
cEmptyCallback=1001
cEmptyTotal=546041
Testing 1 ms delayed sleep callback...
cDelayCallback=1001
cDelayTotal=10746
Maple Mini STM32 board at 70MHz -O3 code optimization
==================================
Testing empty sleep callback...
cEmptyCallback=1001
cEmptyTotal=2689973
Testing 1 ms delayed sleep callback...
cDelayCallback=1001
cDelayTotal=10958
esp32 at 240MHz
==================================
Testing empty sleep callback...
cEmptyCallback=1001
cEmptyTotal=492851
Testing 1 ms delayed sleep callback...
cDelayCallback=1001
cDelayTotal=11002
*/
#define _TASK_SLEEP_ON_IDLE_RUN
#include <TaskScheduler.h>
Scheduler ts;
// Callback methods prototypes
void Count();
void Count2();
bool tEmptyOn();
void tEmptyOff();
// Sleep methods prototypes
void sEmpty(unsigned long aT);
// Tasks
Task tCount(1000, -1, &Count, &ts, false, &tEmptyOn, &tEmptyOff);
Task tCount2(1000, -1, &Count2, &ts, false);
void setup() {
Serial.begin(115200);
delay(5000);
ts.setSleepMethod(&sEmpty);
ts.startNow();
Serial.println("Start ...");
delay(1000);
tCount.enable();
}
void sEmpty(unsigned long aT) {
}
bool tEmptyOn() {
Serial.println(" On_Enable ");
Task& CurrentTask = ts.currentTask();
CurrentTask.disable();
return true;
}
void tEmptyOff() {
Serial.println(" Off_Disable ");
tCount.enable();
}
void Count2() {
Serial.println("ASE ASE");
}
void Count() {
Serial.println("SEA SEA");
// Task *t = &tCount2;
// t->disable();
}
void loop() {
// put your main code here, to run repeatedly:
ts.execute();
}