How to use Button Events block correctly?
Issue #409
resolved
I would like to use Push Button Modules with Microblocks to read click double click longpressed,but I cannot read the button state correctly. It is allways output fasle.
The button modules which I used is as bellow.
https://www.amazon.com.au/YwRobot-Push-Button-Modules-Electronic/dp/B07B4851GC
How to use Button Events block correctly?
Thanks.
Comments (4)
-
repo owner -
reporter @John Maloney Many thanks for your quick reply. Now, it works with my ESP32 Dev kit.
-
repo owner That's excellent!
-
repo owner - changed status to resolved
- Log in to comment
Put the desired function (e.g. "button _ pressed" into a "when" hat block. The code under that block is run when the given button gesture occurs. For "long pressed", the code is only run when the button is released. Here is an example using button A:
If these don't work with your external buttons, use the "read digital pin" block to test that the button works as expected. Some hardware buttons are inverted -- that is, their output is high when not pressed and low when pressed. If that's the case with your buttons, you can modify the "_read button" function to return the "not" of the digital pin.