@@ -10,7 +10,7 @@ shows all the uses of the scheduler, for a simpler example, see the timedBlink e
1010To test the interrupt support, wire a switch to pin 2 with pull up/down. Each change of state 
1111will cause an interrupt. 
1212
13- Written by Dave Cherry of thecoderscorner .com in 2017 
13+ Written by Dave Cherry of TheCodersCorner .com in 2017 
1414*/ 
1515
1616#include  < Arduino.h> 
@@ -22,8 +22,6 @@ Written by Dave Cherry of thecoderscorner.com in 2017
2222//  a task, so it's safe to call anything you wish during it's execution.
2323const  int  interruptPin = 2 ;
2424
25- int  taskId = -1 ;
26- 
2725//  When we are not using IoAbstraction with task manager, then if we want to use interrupts, this class
2826//  provides the absolute bare minimum interrupt abstraction. Normally, we'd use IoAbstraction's device
2927//  abstraction capabilities instead.
@@ -40,13 +38,13 @@ void log(const char* logLine) {
4038}
4139
4240/* *
43-  * This is called by taskManager when the interrupt is raised. TaskManager marshalls  the 
41+  * This is called by taskManager when the interrupt is raised. TaskManager marshals  the 
4442 * interrupt into a task, so it is safe to call Serial etc here. Be aware that interrupts 
4543 * handled by taskManager are not completely real time, so only use when some slight delay 
4644 * can be accepted.  
4745 *  
4846 * - Safe usage: change in rotary encoder, button pressed. 
49-  * - Unsafe usage: over temprature  shutdown, safety circuit. 
47+  * - Unsafe usage: over temperature  shutdown, safety circuit. 
5048 */  
5149void  onInterrupt (pintype_t  pin) {
5250	log (" Interrupt triggered" 
@@ -114,7 +112,7 @@ void setup() {
114112    pinMode (interruptPin, INPUT);
115113
116114    // 
117-     //  Now we register some taks , note that on AVR by default there are 6 slots, all others have 10 slots.
115+     //  Now we register some tasks , note that on AVR by default there are 6 slots, all others have 10 slots.
118116    //  this can be changed in TaskManager.h to your preferred setting.
119117    // 
120118
@@ -123,7 +121,7 @@ void setup() {
123121
124122    //  Now we schedule oneSecondPulse() to be called every second.
125123    //  keep hold of the ID as we will later cancel it from running.
126-     taskId = taskManager.scheduleFixedRate (1 , oneSecondPulse, TIME_SECONDS);
124+     taskid_t   taskId = taskManager.scheduleFixedRate (1 , oneSecondPulse, TIME_SECONDS);
127125
128126    // 
129127    //  now we do a yield operation, which is similar to delayMicroseconds but allows other
@@ -133,13 +131,16 @@ void setup() {
133131    taskManager.yieldForMicros (32000 );
134132    log (" Waited 32 milli second with yield in setup" 
135133
136-     //  now schedule a task to run once in 30 seconds
137-     taskManager.scheduleOnce (30000 , [] {
134+ #ifdef  TM_ALLOW_CAPTURED_LAMBDA
135+     //  now schedule a task to run once in 30 seconds, we capture the taskId using a locally captured value. Notice that
136+     //  this only works on 32 bit boards such as ESP*, ARM, mbed etc.
137+     taskManager.scheduleOnce (30000 , [taskId]() {
138138        log (" 30 seconds up, stopping 1 second job" 
139139
140140        //  now cancel the one second job we scheduled earlier
141141        taskManager.cancelTask (taskId);
142142    });
143+ #endif 
143144
144145    //  and another to run repeatedly at 5 second intervals, shows the task slot status
145146    taskManager.scheduleFixedRate (5 , [] {
0 commit comments