2016-03-26 00:47:20 +01:00
|
|
|
# Pin Is Pressed
|
|
|
|
|
2016-06-09 03:14:00 +02:00
|
|
|
Find whether the pin you say is pressed or not pressed.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-06-09 03:14:00 +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 through your body and back into
|
|
|
|
the micro:bit. This is called **completing a circuit**. It's like you're a big wire!
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```sig
|
|
|
|
input.pinIsPressed(TouchPin.P0);
|
|
|
|
```
|
|
|
|
|
2016-06-09 03:14:00 +02:00
|
|
|
## ~hint
|
|
|
|
|
2016-06-10 23:44:49 +02:00
|
|
|
This function works best when the BBC micro:bit is using batteries for power,
|
2016-06-09 03:14:00 +02:00
|
|
|
instead of the USB cable.
|
|
|
|
|
|
|
|
## ~
|
|
|
|
|
2016-03-26 00:47:20 +01:00
|
|
|
### Parameters
|
|
|
|
|
2016-06-09 03:14:00 +02:00
|
|
|
* a [string](/reference/types/string) that holds the pin name (**P0**, **P1**, or **P2**)
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
### returns
|
|
|
|
|
2016-06-09 03:14:00 +02:00
|
|
|
* a [boolean](/reference/types/boolean) that means whether the pin you say is pressed (`true` or `false`)
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
### Example
|
|
|
|
|
2016-06-09 03:14:00 +02:00
|
|
|
This program shows `1` if `P0` is pressed, and `0` if `P0` is not pressed:
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
|
|
|
if (input.pinIsPressed(TouchPin.P0)) {
|
|
|
|
basic.showNumber(1, 150)
|
|
|
|
} else {
|
|
|
|
basic.showNumber(0, 150)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### See also
|
|
|
|
|
2016-04-18 18:47:34 +02:00
|
|
|
[BBC micro:bit pins](/device/pins), [on pin pressed](/reference/input/on-pin-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-03-26 00:47:20 +01:00
|
|
|
|