How to wait on multiple events, in parallel?

  • 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?


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

  • Excellent, thanks @world101 !