2017-09-11 19:49:40 +02:00
# Smiley Buttons
2016-06-11 20:40:09 +02:00
## Step 1
2017-09-11 19:49:40 +02:00
Place a ``||input:on button pressed||`` block to run code when button **A** is pressed.
2016-06-11 20:40:09 +02:00
```blocks
2017-09-11 19:49:40 +02:00
input.onButtonPressed(Button.A, () => {
});
2016-06-11 20:40:09 +02:00
```
## Step 2
2018-08-17 16:58:45 +02:00
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
2016-10-13 20:32:25 +02:00
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
2016-12-08 09:10:00 +01:00
# # . # #
# # . # #
2016-10-13 20:32:25 +02:00
. . . . .
2016-12-08 09:10:00 +01:00
# . . . #
. # # # .`
2016-10-13 20:32:25 +02:00
);
2016-06-11 20:40:09 +02:00
});
```
## Step 3
2018-09-14 23:57:17 +02:00
Add ``||input:on button pressed||`` and ``||basic:show leds||`` blocks to display a frowny 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-10-13 20:32:25 +02:00
. . . . .
2016-12-08 09:10:00 +01:00
. # # # .
# . . . #`
2016-10-13 20:32:25 +02: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
2018-08-17 16:58:45 +02:00
## Step 4
2017-09-11 19:49:40 +02:00
2018-09-14 23:57:17 +02:00
Add a secret mode that happens when **A** and **B** are pressed together. For this 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(`
. . . . .
. . # . #
. . . . .
# . . . #
. # # # .
`)
})
```
2018-08-17 16:58:45 +02:00
## 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
2018-08-17 16:58:45 +02:00
Nice! Now go and show it off to your friends!
2016-12-08 18:16:27 +01:00