🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Problem with button input during loop. (interupt loop)

    UIFlow
    3
    4
    558
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      shiva
      last edited by

      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

      felmueF S 2 Replies Last reply Reply Quote 0
      • felmueF
        felmue @shiva
        last edited by felmue

        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

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        1 Reply Last reply Reply Quote 0
        • S
          shiva @shiva
          last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • P
            peolsolutions
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post