mikaelpatel / Arduino-Scheduler

Portable Cooperative Multi-tasking Scheduler for Arduino
https://mikaelpatel.github.io/Arduino-Scheduler/
164 stars 41 forks source link

Rocketscream Low Power Sleep example #27

Closed sslupsky closed 6 years ago

sslupsky commented 6 years ago

Do you have any advice regarding compatibility with low power sleep? How would one go about using LowPower.sleep() using the scheduler? Would it simply be to create a sleep task that calls LowPower.sleep()? Is there a way to set task priority so the sleep task is the lowest priority task?

mikaelpatel commented 6 years ago

@sslupsky It is possible to call low power sleep from, for instance, the main task. The task loop() function should also contain a call to yield(). The drawback is that other active tasks (e.g. not waiting for a condition or timeout) will be delayed as there is no task priority. One way to avoid this is to only call low power sleep when all other tasks are waiting for a timeout (i.e. have called delay()) or to implement priority queues.

Ref. https://github.com/rocketscream/Low-Power