pxt-calliope/docs/projects/smiley-buttons.md
Sam El-Husseini 2e9cb3c43b
Fix tutorial authoring for getting started (#885)
* Fix tutorial authoring for getting started

Remove extra new lines

* Fix other tutorials
2018-06-21 16:02:19 -07:00

80 lines
1.6 KiB
Markdown

# Smiley Buttons
## Step 1
Place a ``||input:on button pressed||`` block to run code when button **A** is pressed.
```blocks
input.onButtonPressed(Button.A, () => {
});
```
## Step 2
Place a ``||basic:show leds||`` block inside ``||input:on button pressed||`` to display a smiley on the screen.
```blocks
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
# # . # #
# # . # #
. . . . .
# . . . #
. # # # .`
);
});
```
## Step 3
Click ``|Download|`` to transfer your code in your @boardname@ and try pressing button **A**.
## Step 4
Add ``||input:on button pressed||`` and ``||basic:show leds||`` blocks to display a frowney when button **B** is pressed.
```blocks
input.onButtonPressed(Button.B, () => {
basic.showLeds(`
# # . # #
# # . # #
. . . . .
. # # # .
# . . . #`
);
});
```
## Step 5
Click ``|Download|`` to transfer your code in your @boardname@ and try pressing button A or B.
## Step 6
Add a secret mode where ``A`` and ``B`` are pressed together. In that case, add multiple ``||basic:show leds||`` blocks to create an animation...
```blocks
input.onButtonPressed(Button.AB, () => {
basic.showLeds(`
. . . . .
# . # . .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. . # . #
. . . . .
# . . . #
. # # # .
`)
})
```
## Step 7
Click ``|Download|`` to transfer your code in your @boardname@
and show it off to your friends!