Problem with button input during loop. (interupt loop)
-
Hello,
I have developed a productivity timer application and am encountering two issues related to interrupting a loop that includes a sleep operation.
Interrupt Timing: Currently, to interrupt the loop using a button press, the button must be triggered at the precise moment the event occurs within the loop. This makes it very difficult to reliably interrupt the loop as intended.
Label Update After Interruption: When the loop is successfully paused, a display label (label 0) still updates once more with a lower value before halting, which is unintended.
Could you please advise how I might improve the code to:Allow the loop to be interrupted at any time, rather than requiring precise timing, and
Prevent the label from updating after the interruption is triggered?
Thank you in advance for your assistance.Here is a link to my projectL https://uiflow2.m5stack.com/?pkey=afd1587cf202443388b62587e6c3744e
-
Hello @shiva
please have a look in Project Zone example: M5StickCPlus2_UseTimerToCountSeconds_UIFlow2.2.4
It shows how to use a timer (instead of sleep) to count. Using a timer makes sure a button press is honored all the time.
Thanks
Felix -
@shiva said in Problem with button input during loop. (interupt loop):
Hello,
I have developed a productivity timer application and am encountering two issues related to interrupting a loop that includes a sleep operation.
Interrupt Timing: Currently, to interrupt the loop using a button press, the button must be triggered at the precise moment the event occurs within the loop. This makes it very difficult to reliably interrupt the loop as intended.
Label Update After Interruption: When the loop is successfully paused, a display label (label 0) still updates once more with a lower value before halting, which is unintended.
Could you please advise how I might improve the code to:Allow the loop to be interrupted at any time, rather than requiring precise timing, and
Prevent the label from updating after the interruption is triggered?
Thank you in advance for your assistance.Here is a link to my projectL https://uiflow2.m5stack.com/?pkey=afd1587cf202443388b62587e6c3744e
Thank you, this is what I am looking for. Do you have a link to the documentation for Timer? I want to create a countdown timer.