Multiple timers whilst sleeping with WakeUpPin

Hi there,

I am very new to programming these kind of devices, and I am trying to build a little project to get myself good.

In simple terms, I want a device that will flash green when turned on, go to sleep for 30 minutes (cellular off), wake up and then flash green again, and repeat.
However, if someone presses the button during this time, it will wake up, flash red, wait to ensure no more input, publish button presses to the cloud, then go back to sleep for the remainder of the 30 minutes.

I have got most of it complete, but I am at a loss with the timers. I know they can be set for x amount of time, or set to break on wakeUpPin. Or both… but the timer wont start where it left off, it restarts, so if someone pressed the button at 29 minutes, it will run for 59 minutes in total.

I thought about setting up two timers, but the second one stops counting when the device goes to sleep. Is there anyway out around this? Or am I missing something obvious?

Any help will be greatly appreciated. I’ve been pulling my hair out for days at this.

Thank you!!

Chris

You need a variable to keep track of when you put your device to sleep, so that when it is awakened by a button press, you can calculate the amount of time that has elapsed. With that number, you can adjust the time on the next sleep command appropriately.

1 Like

Thank you very much.

I will give this a try!

1 Like