on Event
Run some code when a button (A
, B
, or both A
+ B
) is clicked, double clicked, or has some other action.
input.buttonA.onEvent(ButtonEvent.Click, () => {
})
Touch
If your board has pins or pads that work as touch inputs, then your code can use them just like buttons.
Instead of saying button A
or button B
as the input source, use a pin name like pin A1
.
input.pinA1.onEvent(ButtonEvent.Down, function() {
console.log("Press down")
})
Read about touch sensors and using the pins as touch buttons.
Parameters
ev
the button action to run some code for. The button actions (events) are:
click
: button was clicked (pressed and released)
double click
: button is clicked two times really fast (pressed and released, twice but quickly)
long click
: button is pressed and released after being held down for a long time, like one second or longer
up
: button is released from just being pressed
down
: button is just pressed down
held
: button was pressed and is still pressed
body
the code you want to run when something happens with a button
Examples
Button release
Wnen the B
button is released, log a message.
input.buttonB.onEvent(ButtonEvent.Up, function() {
console.log("Release button")
})
Touch down
Log a message when you touch or release the capacitive pin pin A1
on the board.
input.pinA1.onEvent(ButtonEvent.Down, function() {
console.log("Touch pin")
})
input.pinA1.onEvent(ButtonEvent.Up, function() {
console.log("Release pin")
})
See also
is pressed,
was pressed,
random
Touch sensors