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.
-
To interrupt a loop using a button input, ensure the program continuously checks the button state within the loop. If the loop doesn't monitor inputs regularly, it may miss the button press. Use flags or conditions triggered by the button to break or exit the loop immediately when pressed.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login