1. The FiberBot Googly Sounds sample program we will build does three
things:
It makes the LED “googly eye” animation move in the direction you
tilt it.
It makes the eye roll around if you shake it.
It plays one of three random robot sounds if you speak to it or make
another loud sound.
The algorithm for the program might look like this:
Check to see which way the micro:bit is facing. Also listen for a
loud sound.
If the micro:bit is held facing the ceiling, show an “eye” in the
center of the LED grid.
If the micro:bit is facing left, or right, move the “eye” to that side
of the LED grid.
If the micro:bit is facing you, right side up, let the “eye” fall to the
bottom of the grid. If its upside down, let the “eye” slide to the
top of the grid.
then click “Duplicate.
Pull a stack of blocks apart from underneath.
To delete a block, drag it over the column of block categories.
You can type words or numbers right into an oval-shaped
white space.
You can drag pointy-ended or oval-shaped blocks into the
same shape spaces on other blocks to make them snap into
place.
To download your MakeCode program to your micro:bit,
connect the board to your computer with a micro USB data
cable. (Be sure to use a data cable. A regular charging cable
won’t work!) For more tips, see the box “How to Download
MakeCode to the micro:bit” on page 139.
132
Making Simple Robots, 2nd Edition
Make_Simple_Robots_interior_FIN.indd 132Make_Simple_Robots_interior_FIN.indd 132 4/26/22 1:56 PM4/26/22 1:56 PM
If the micro:bit is shaken, make the “eye” roll around the outside
of the LED grid.
If the micro:bit detects a loud sound, pick a random number
from 1–3.
Play a different sound depending on the number picked.
Once you understand how it works, feel free to program in your own inputs,
animations, and sounds!
2. Open MakeCode (makecode.microbit.org), click “New Project,” and give
it a name. The editing screen will open and you can begin to build your
program.
3. Begin with the “on start” block thats already in your workspace
(Figure
A
)
. To make sure your micro:bit googly eye is always in the center when
you turn it on:
A
Chapter 4: Making Robots Likable 133
Make_Simple_Robots_interior_FIN.indd 133Make_Simple_Robots_interior_FIN.indd 133 4/26/22 1:56 PM4/26/22 1:56 PM
Open the Basic menu (blue).
Drag a “show leds” block inside the “on start” block
(Figure
B
)
.
Draw the eye by clicking on the lights in the grid to turn them on.
The eye in the example is a square of 3 by 3 lights, right in the
middle of the grid.
4. You will need a lot of eye images for this project, so right click on the
show leds” block and duplicate it. It will look gray and see-through, like
a ghost, until you add it to a stack that tells it when to run
(Figure
C
)
.
5. To make the micro:bit eye move around just like the real googly eye
(Figure
D
)
:
Open the Input menu and drag the “on [shake]” block into the
workspace.
Snap it around the duplicate “show leds” block.
Click on the little triangle-arrow next to the word “shake” to open a
drop-down menu of different conditions measured by the tilt sensor
(the accelerometer)
(Figure
E
)
.
B
134
Making Simple Robots, 2nd Edition
Make_Simple_Robots_interior_FIN.indd 134Make_Simple_Robots_interior_FIN.indd 134 4/26/22 1:56 PM4/26/22 1:56 PM
C
D
E
Chapter 4: Making Robots Likable 135
Make_Simple_Robots_interior_FIN.indd 135Make_Simple_Robots_interior_FIN.indd 135 4/26/22 1:56 PM4/26/22 1:56 PM
Choose“screen up.” When the FiberBot is in this position, it will face
the ceiling, and the digital googly eye will be resting in the middle of
the micro:bit’s LED grid
(Figure
F
)
. (You can check if the positions
you program are correct by looking at how the real googly eye
moves around!).
6. Now, to make the eye move when you tilt the board:
Right click on the outer “on screen up” block and duplicate the
entire mini-stack. It will also look like a ghost, because you already
have a block that says “screen up.” So change it to another choice:
“tilt left
(Figure
G
).
To move the eye to the left, click on the lights you need to turn on.
Then click on the already-lit LED squares you need to turn off. In this
case, you will turn on the column of lights next to the left side of the
eye, and turn off the lights on the right side.
Stop and test your program on the micro:bit simulation. Notice that
if you mouse over or click on the left side of the simulated board,
the animation tilts to the left. Does the eye design move to the left?
F
136
Making Simple Robots, 2nd Edition
Make_Simple_Robots_interior_FIN.indd 136Make_Simple_Robots_interior_FIN.indd 136 4/26/22 1:56 PM4/26/22 1:56 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.8.247