2016-08-09 00:23:18 +02:00
|
|
|
# On Pin Released
|
|
|
|
|
|
|
|
Start an [event handler](/reference/event-handler) (part of the
|
|
|
|
program that will run when something happens, like when a button is
|
|
|
|
pressed). This handler works when you release pin `0`, `1`, or `2`
|
|
|
|
together with `GND`. When you are using this function in a web
|
2016-11-02 01:44:37 +01:00
|
|
|
browser, click and release the pins on the screen instead of the ones on the
|
|
|
|
@boardname@.
|
2016-08-09 00:23:18 +02:00
|
|
|
|
|
|
|
If you hold the `GND` pin with one hand and touch pin `0`, `1`, or `2`
|
|
|
|
with the other, a very small (safe) amount of electricity will flow
|
2016-11-02 01:44:37 +01:00
|
|
|
through your body and back into the @boardname@. This is called
|
2016-08-09 00:23:18 +02:00
|
|
|
**completing a circuit**. It's like you're a big wire!
|
|
|
|
|
|
|
|
```sig
|
2020-08-19 22:03:58 +02:00
|
|
|
input.onPinReleased(TouchPin.P0, () => {
|
2016-08-09 00:23:18 +02:00
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
## ~hint
|
|
|
|
|
2016-11-01 18:42:42 +01:00
|
|
|
This function works best when the @boardname@ is using batteries for power,
|
2016-08-09 00:23:18 +02:00
|
|
|
instead of the USB cable.
|
|
|
|
|
|
|
|
## ~
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
|
|
|
|
* ``name`` means the pin that is being released, either `P0`, `P1`, or `P2`
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## Example: pin pressed counter
|
2016-08-09 00:23:18 +02:00
|
|
|
|
|
|
|
This program counts how many times you release the `P0` pin.
|
|
|
|
Every time you release the pin, the program shows the number of times on the screen.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
let count = 0
|
|
|
|
basic.showNumber(count, 100)
|
2020-08-19 22:03:58 +02:00
|
|
|
input.onPinReleased(TouchPin.P0, () => {
|
2016-08-09 00:23:18 +02:00
|
|
|
count = count + 1
|
|
|
|
basic.showNumber(count, 100)
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## See also
|
2016-08-09 00:23:18 +02:00
|
|
|
|
2016-11-01 18:42:42 +01:00
|
|
|
[@boardname@ pins](/device/pins), [pin is pressed](/reference/input/pin-is-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)
|
2016-08-09 00:23:18 +02:00
|
|
|
|