This function works best when the Calliope mini is using batteries for power, instead of the USB cable.
On Pin Event
Start an event handler (part of the
program that will run when something happens, like when a button is
pressed). This handler works when you touch pin 0
, 1
, or 2
together with GND
, and release it within 1 second. You can choose another event type by using
the button event block. Possible event types are pressed down
(1), released up
(2), clicked
(3), long clicked
(4) or hold
(5).
When you are using this function in a web
browser, click the pins on the screen instead of the ones on the
Calliope mini.
If you hold the GND
pin with one hand and touch pin 0
, 1
, 2
or 3
with the other, a very small (safe) amount of electricity will flow
through your body and back into the Calliope mini. This is called
completing a circuit. It’s like you’re a big wire!
input.onPinTouchEvent(TouchPin.P0, input.buttonEventClick(), () => {
})
Parameters
name
means the pin that is being pressed, eitherP0
,P1
, orP2
Pin presses in action
See how the Calliope mini detects a press at a pin or on something connected to a pin in this video:
Example: pin pressed counter
This program counts how many times you press the P0
pin.
Every time you press the pin, the program shows the number of times on the screen.
let count = 0
basic.showNumber(count)
input.onPinTouchEvent(TouchPin.P0, input.buttonEventClick(), () => {
count = count + 1
basic.showNumber(count)
})
See also
Calliope mini pins, pin is pressed, analog read pin, analog write pin, digital read pin, digital write pin, button event block