2017-09-11 10:49:40 -07:00
# Smiley Buttons
2016-06-11 14:40:09 -04:00
2018-10-10 15:38:51 -07:00
## Introduction @unplugged
Code the buttons on the @boardname @ to show that it's happy or sad.
2018-12-02 07:58:43 -08:00
(Want to learn how the buttons works? [Watch this video ](https://youtu.be/t_Qujjd_38o )).
2018-10-10 15:38:51 -07:00
2018-12-02 07:58:43 -08:00
![Pressing the A and B buttons ](/static/mb/projects/smiley-buttons/sim.gif )
2018-10-10 15:38:51 -07:00
2018-10-10 09:00:56 -07:00
## Step 1 @fullscreen
2016-06-11 14:40:09 -04:00
2017-09-11 10:49:40 -07:00
Place a ``||input:on button pressed||` ` block to run code when button **A** is pressed.
2016-06-11 14:40:09 -04:00
```blocks
2017-09-11 10:49:40 -07:00
input.onButtonPressed(Button.A, () => {
});
2016-06-11 14:40:09 -04:00
```
2018-10-10 09:00:56 -07:00
## Step 2 @fullscreen
2016-06-11 14:40:09 -04:00
2018-08-17 07:58:45 -07: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 14:40:09 -04:00
```blocks
2016-10-13 11:32:25 -07:00
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
2016-12-08 00:10:00 -08:00
# # . # #
# # . # #
2016-10-13 11:32:25 -07:00
. . . . .
2016-12-08 00:10:00 -08:00
# . . . #
. # # # .`
2016-10-13 11:32:25 -07:00
);
2016-06-11 14:40:09 -04:00
});
```
2018-10-10 09:00:56 -07:00
## Step 3 @fullscreen
2016-06-11 14:40:09 -04:00
2018-09-14 14:57:17 -07:00
Add ``||input:on button pressed||`` and ``||basic:show leds||` ` blocks to display a frowny when button **B** is pressed.
2016-06-11 14:40:09 -04:00
```blocks
input.onButtonPressed(Button.B, () => {
basic.showLeds(`
2016-12-08 00:10:00 -08:00
# # . # #
# # . # #
2016-10-13 11:32:25 -07:00
. . . . .
2016-12-08 00:10:00 -08:00
. # # # .
# . . . #`
2016-10-13 11:32:25 -07:00
);
2016-06-11 14:40:09 -04:00
});
2016-06-25 17:22:50 -04:00
```
2016-12-08 00:10:00 -08:00
2018-10-10 09:00:56 -07:00
## Step 4 @fullscreen
2017-09-11 10:49:40 -07:00
2018-09-14 14:57:17 -07: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 05:44:28 -07:00
```blocks
input.onButtonPressed(Button.AB, () => {
basic.showLeds(`
. . . . .
# . # . .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. . # . #
. . . . .
# . . . #
. # # # .
`)
})
```
2018-08-17 07:58:45 -07: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 00:10:00 -08:00
2018-08-17 07:58:45 -07:00
Nice! Now go and show it off to your friends!
2016-12-08 09:16:27 -08:00