Rewrote in simple language. Fixed some typos.

This commit is contained in:
Ron Hale-Evans 2016-06-10 14:44:49 -07:00
parent c6f5a8dcc6
commit 8841c47638
2 changed files with 18 additions and 4 deletions

View File

@ -1,17 +1,31 @@
# On Pin Pressed
Register an [event handler](/reference/event-handler) that will execute whenever the user holds the `GND` pin with one hand, and presses pin `0`, `1`, or `2` with the other hand, thus completing a circuit; when you run a script with this function in a web browser, click pins 0 , 1, or 2 on the simulator.
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 press pin `0`, `1`, or `2` together with `GND`.
When you are using this function in a web browser, click the pins on the screen instead of the ones
on the BBC micro:bit.
*Note* that this function works best when the BBC micro:bit is powered by AAA battery.
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!
```sig
input.onPinPressed(TouchPin.P0, () => {
})
```
## ~hint
This function works best when the BBC micro:bit is using batteries for power,
instead of the USB cable.
## ~
### Example: pin pressed counter
This example counts how many times the P0 pin is pressed. Each time the pin is pressed, the global count variable is increased by 1 and displayed on the screen.
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.
```blocks
let count = 0

View File

@ -12,7 +12,7 @@ input.pinIsPressed(TouchPin.P0);
## ~hint
This function works best when the BBC:microbit is using batteries for power,
This function works best when the BBC micro:bit is using batteries for power,
instead of the USB cable.
## ~