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?Thanks
Mike -
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 !
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