2016-06-14 17:12:13 +02:00
|
|
|
# smiley buttons
|
|
|
|
|
2016-11-10 17:37:13 +01:00
|
|
|
### ~avatar
|
2016-06-11 20:40:09 +02:00
|
|
|
|
2016-11-10 17:37:13 +01:00
|
|
|
Use buttons to show a smiley face!
|
|
|
|
|
|
|
|
### ~
|
2016-06-11 20:40:09 +02:00
|
|
|
|
|
|
|
## Step 1
|
|
|
|
|
2016-06-14 23:20:45 +02:00
|
|
|
Use [show leds](/reference/basic/show-leds) to make a smiley face:
|
2016-06-11 20:40:09 +02:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.showLeds(`
|
2016-10-13 20:32:25 +02:00
|
|
|
. # . # .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
# . . . #
|
|
|
|
. # # # .`
|
|
|
|
);
|
2016-06-11 20:40:09 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
## Step 2
|
|
|
|
|
|
|
|
Add an input block for when [button A is pressed](/reference/input/button-is-pressed), and put a
|
|
|
|
frowny face inside it:
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.showLeds(`
|
|
|
|
. # . # .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
2016-10-13 20:32:25 +02:00
|
|
|
# . . . #
|
|
|
|
. # # # .`
|
|
|
|
);
|
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
|
basic.showLeds(`
|
|
|
|
. # . # .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. # # # .
|
|
|
|
# . . . #`
|
|
|
|
);
|
2016-06-11 20:40:09 +02:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
## Step 3
|
|
|
|
|
|
|
|
Now add blocks so that when [button B is pressed](/reference/input/button-is-pressed), a smiley appears:
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.showLeds(`
|
|
|
|
. # . # .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
2016-10-13 20:32:25 +02:00
|
|
|
# . . . #
|
|
|
|
. # # # .`
|
|
|
|
);
|
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
|
basic.showLeds(`
|
|
|
|
. # . # .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. # # # .
|
|
|
|
# . . . #`
|
|
|
|
);
|
2016-06-11 20:40:09 +02:00
|
|
|
});
|
|
|
|
input.onButtonPressed(Button.B, () => {
|
|
|
|
basic.showLeds(`
|
2016-10-13 20:32:25 +02:00
|
|
|
. # . # .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
# . . . #
|
|
|
|
. # # # .`
|
|
|
|
);
|
2016-06-11 20:40:09 +02:00
|
|
|
});
|
2016-06-25 23:22:50 +02:00
|
|
|
```
|