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

80 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.
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
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.
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 5
2016-12-08 09:10:00 +01:00
Click ``|Download|`` to transfer your code in your @boardname@ and try pressing button A or B.
2017-03-28 14:44:28 +02:00
## 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...
2017-03-28 14:44:28 +02:00
```blocks
input.onButtonPressed(Button.AB, () => {
basic.showLeds(`
. . . . .
# . # . .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. . # . #
. . . . .
# . . . #
. # # # .
`)
})
```
## Step 7
2016-12-08 09:10:00 +01:00
Click ``|Download|`` to transfer your code in your @boardname@
and show it off to your friends!
2016-12-08 18:16:27 +01:00