pxt-calliope/docs/projects/smiley-buttons.md

75 lines
1.6 KiB
Markdown
Raw Normal View History

# Smiley Buttons
2016-06-11 20:40:09 +02:00
## Step 1
Place a ``||input:on button pressed||`` block to run code when button **A** is pressed.
2016-06-11 20:40:09 +02:00
```blocks
input.onButtonPressed(Button.A, () => {
});
2016-06-11 20:40:09 +02:00
```
## Step 2
Place a ``||basic:show leds||`` block inside ``||input:on button pressed||`` to display a smiley on the screen. Press the **A** button in the simulator to see the smiley.
2016-06-11 20:40:09 +02:00
```blocks
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
2016-12-08 09:10:00 +01:00
# # . # #
# # . # #
. . . . .
2016-12-08 09:10:00 +01:00
# . . . #
. # # # .`
);
2016-06-11 20:40:09 +02:00
});
```
## Step 3
Add ``||input:on button pressed||`` and ``||basic:show leds||`` blocks to display a frowney when button **B** is pressed.
2016-06-11 20:40:09 +02:00
```blocks
input.onButtonPressed(Button.B, () => {
basic.showLeds(`
2016-12-08 09:10:00 +01:00
# # . # #
# # . # #
. . . . .
2016-12-08 09:10:00 +01:00
. # # # .
# . . . #`
);
2016-06-11 20:40:09 +02:00
});
2016-06-25 23:22:50 +02:00
```
2016-12-08 09:10:00 +01:00
## Step 4
Add a secret mode that happens when **A** and **B** are pressed together. In that case, add multiple ``||basic:show leds||`` blocks to create an animation...
2017-03-28 14:44:28 +02:00
```blocks
input.onButtonPressed(Button.AB, () => {
basic.showLeds(`
. . . . .
# . # . .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. . # . #
. . . . .
# . . . #
. # # # .
`)
})
```
## Step 5
If you have a @boardname@, connect it to USB and click ``|Download|`` to transfer your code. Press button **A** on your @boardname@. Try button **B** and then **A** and **B** together.
## Step 6
2016-12-08 09:10:00 +01:00
Nice! Now go and show it off to your friends!
2016-12-08 18:16:27 +01:00