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

    How to wait on multiple events, in parallel?

    UIFlow
    2
    3
    3.6k
    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.
    • M
      mb
      last edited by

      Hi all,
      I would like to wait for user interaction, either a display touch or RFID card - at the same time, in parallel. How can this be done?

      Thanks
      Mike

      1 Reply Last reply Reply Quote 0
      • world101W
        world101
        last edited by

        It depends on what you want your program to do. Do you want to halt all activity until the user interacts with the display or an RFID card is scanned? Are there other events going on while waiting for user interaction (like some other functions or calculations)?

        The way I would design it in uiFlow (assuming you have the Core2) is to use timer callbacks set to about 100ms to check the RFID state ("card near" block true/false) and button call backs for display touch. You could also use the "Get touch" blocks, but then you would also need another timer to check for the touch state.

        When using multiple timers, I like to offset the timers by a some odd number of ms to reduce the chance of them firing at exactly the same time (i.e. 100ms and 133ms). The wait() and wait_ms() functions are blocking and should be avoided if possible. I learned this from working with Blynk, where blocking applications or functions are strongly discouraged. Timers become your friend to reduce the chance of blocking code.

        1 Reply Last reply Reply Quote 1
        • M
          mb
          last edited by

          Excellent, thanks @world101 !

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