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
|
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
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
|
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
|
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
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-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
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
## Step 5
|
2016-12-08 09:10:00 +01:00
|
|
|
|
2017-09-11 19:49:40 +02: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
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
## Step 6
|
|
|
|
|
|
|
|
Add a secret mode where ``A`` and ``B`` are pressed together.
|
2017-08-10 07:00:53 +02:00
|
|
|
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(`
|
|
|
|
. . . . .
|
|
|
|
. . # . #
|
|
|
|
. . . . .
|
|
|
|
# . . . #
|
|
|
|
. # # # .
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
## Step 7
|
2016-12-08 09:10:00 +01:00
|
|
|
|
2017-09-11 19:49:40 +02: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
|
|
|
|