finish second lesson

This commit is contained in:
Tom Ball 2016-06-11 14:40:09 -04:00
parent 5a2896808e
commit 346ec3d1a6
4 changed files with 115 additions and 0 deletions

View File

@ -1,5 +1,7 @@
# Projects # Projects
![](/static/mb/projects/all10.png)
![](/static/mb/projects/a1-display.png) ![](/static/mb/projects/a1-display.png)
[Flashing Heart](/projects/flashing-heart) [Flashing Heart](/projects/flashing-heart)

View File

@ -0,0 +1,67 @@
![](/static/mb/projects/a2-buttons.png)
Use buttons to show a smiley or frowny face.
## Step 1
Use [show leds](/reference/basic/showLeds) to make a smiley face:
```blocks
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .`);
```
## 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(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .`);
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
. # . # .
. # . # .
. . . . .
. # # # .
# . . . #`);
});
```
## Step 3
Now add blocks so that when [button B is pressed](/reference/input/button-is-pressed), a smiley appears:
```blocks
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .`);
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
. # . # .
. # . # .
. . . . .
. # # # .
# . . . #`);
});
input.onButtonPressed(Button.B, () => {
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .`);
});
```

View File

@ -46,3 +46,49 @@ basic.pause(500);
basic.clearScreen(); basic.clearScreen();
}) })
``` ```
## Step 4
Add a [pause](/reference/basic/pause) to wait after clearing the screen.
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
basic.pause(500);
basic.clearScreen();
basic.pause(500);
})
```
## Step 5
Add a second image of a broken heart.
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
basic.pause(500);
basic.clearScreen();
basic.pause(500);
basic.showLeds(`
. # . # .
# . # # #
# . . . #
. # # # .
. . # . .`);
basic.pause(500);
basic.clearScreen();
basic.pause(500);
})
```

BIN
docs/static/mb/projects/all10.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 KiB