How to use Button Events block correctly?

Issue #409 resolved
Tom Ming created an issue

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)

  1. John Maloney repo owner

    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:

    allScripts709659.png Be sure to click the "run" button to start the "when" hats. (They should get a green highlight.)

    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.

  2. Log in to comment