pxt-calliope/docs/getting-started/buttons.md

81 lines
1.8 KiB
Markdown
Raw Normal View History

2016-06-24 08:52:24 +02:00
# Button A and button B
### ~avatar avatar
Buttons are great to build games!
### ~
This program will show the word **ANTEATER** on the LED
screen when you press button `A`.
```blocks
input.onButtonPressed(Button.A, () => {
basic.showString("ANTEATER");
});
```
#### ~hint
The ``showString`` block can show letters, numbers, and punctuation
on the @boardname@ screen.
2016-06-24 08:52:24 +02:00
#### ~
Now try to unscramble these blocks in the editor so that the @boardname@
2016-06-24 08:52:24 +02:00
shows **BANANA** when you press button `B`.
```shuffle
input.onButtonPressed(Button.B, () => {
basic.showString("BANANA");
});
```
#### ~hint
You can find the letter `B` by clicking the letter `A` on the
``onButtonPressed`` block.
#### ~
2016-11-02 01:44:37 +01:00
Click **Download** to move your program to the @boardname@!
2016-06-24 08:52:24 +02:00
#### Your turn!
Can you combine these blocks so your program shows your real name
instead of **ANTEATER** when you press `A`, but _your secret agent
name_ instead of **BANANA** when you press `B`?
### Pins
You can also use the pins as buttons. (The pins are the holes in the
2016-11-02 01:44:37 +01:00
metal stripe at the bottom of the @boardname@ board.) For example, hold
2016-06-24 08:52:24 +02:00
the ``GND`` button with one hand and touch the ``0`` pin (called
2016-11-02 01:44:37 +01:00
``P0``) with your other hand to tell the @boardname@ you're pressing it.
2016-06-24 08:52:24 +02:00
Unscramble the blocks in the editor to show a heart when you touch
pin ``P0``.
```shuffle
input.onPinPressed(TouchPin.P0, () => {
basic.showLeds(`
. # . # .
# . # . #
# . . . #
. # . # .
. . # . .`);
});
```
Click **Download** to move your program to the @boardname@!
2016-06-24 08:52:24 +02:00
## ~hint
Try this experiment: find a friend and hold hands. Touch the ``GND``
pin while your friend presses the ``P0`` pin. You should see the
heart! The electric current is going through your bodies and across
your handshake to make it happen!
## ~
2016-06-24 22:27:34 +02:00
### ~button /getting-started/shake
NEXT: SHAKE
### ~