Does it go back to the middle when you let the board go flat again? If
it does, then your code is working!
Follow the same steps to make the eye move in other directions
(Figure
H
)
:
tilt right
logo down (the logo
is the little oval face
at the top of the
micro:bit, so “logo
down” means the
FiberBot is standing
on its head.
logo up.
G
H
Chapter 4: Making Robots Likable 137
Make_Simple_Robots_interior_FIN.indd 137Make_Simple_Robots_interior_FIN.indd 137 4/26/22 1:56 PM4/26/22 1:56 PM
If you want to, you can also do “screen down,” but you’d have to hold the
FiberBot over your head to see it! (Where should the eye be if the screen
points straight down?)
7. At this point, the googly eye motion is complete! Before moving onto
some sillier animated moves, stop and download the code to your
micro:bit to watch how it works on the real thing! See the “How to
Download MakeCode to the micro:bit” box on page 139 for instructions.
You can work with the micro:bit right on the FiberBot. If the masking
tape loses its grip, just replace it when you’re done.
8. Just for fun, create another stack of code that makes the googly eye
roll around when you shake the robot. To do that, you’ll stack a series of
show leds” blocks. When the program runs, the blocks will act like the
frames of an animated film — as they appear one after the other, it will
look like the eye is moving! Here’s what to do:
Duplicate the “on [screen up]” block again, with the “show leds
block that displays the eye in the middle of the grid. This time,
change the movement back to “shake”
(Figure
I
).
Now duplicate just the “show leds” block. Drag the duplicate right
below the first block, inside the mouth of the “on [shake]” block.
The mouth will open wider as you add more blocks. Change the
lights on the second block to show the eye at the bottom of the grid
(Figure
J
)
.
I J
138
Making Simple Robots, 2nd Edition
Make_Simple_Robots_interior_FIN.indd 138Make_Simple_Robots_interior_FIN.indd 138 4/26/22 1:56 PM4/26/22 1:56 PM
How to Download MakeCode to
the micro:bit
1. The file type for
micro:bit programs
ends with a “.hex”
suffix. The basic
steps to download
the .hex code to your
board are:
Plug a USB data
cable into the
micro:bit and your computer.
Click the purple “Download” button on the bottom left of the
MakeCode screen).
Move the .hex file from your computer onto the micro:bit
drive.For instructions on how to download a MakeCode
program with your browser, check out makecode.microbit.
org/device/usb.) The example here shows what to do if you
use a Chrome browser:
Look for the file name at the bottom of your browser
window.
Click the V-arrow next to the file name to make a menu
pop up. Choose “Show in folder.”
Open the file explorer on your computer. The .hex file
may appear in the Downloads folder.
Chapter 4: Making Robots Likable 139
Make_Simple_Robots_interior_FIN.indd 139Make_Simple_Robots_interior_FIN.indd 139 4/26/22 1:56 PM4/26/22 1:56 PM
Duplicate and move the second block the same way. Change the
lights to show the eye in the
bottom left corner
(Figure
K
)
.
Keep going, duplicating the blocks
and moving the eye all around
the grid. End with the eye in the
middle again
(Figure
L
)
.
Test your program by “shaking”
the simulated micro:bit on the
screen. Then download it to the
real board to see how it looks.
Make any changes you think it
needs
(Figure
M
).
At this point, your stack of blocks
is pretty long! To tidy it up, right
click on the “on [shake]” block.
When the menu pops up, choose
Look for a drive on your computer labeled MICROBIT.
Drag the .hex file (or copy and paste it) to the MICROBIT
drive. That’s it! A light on the micro:bit board will pulse on
and off for a few seconds, and then the program should
start to run.
NOTE: On some computers, you can “pair” the board so that
.hex files move to the micro:bit automatically. This is a handy
shortcut, but it’s not a good idea if you also like to save the
.hex files to another folder on your computer. To set up the
pairing option, look for the instructions on the “Download
Complete” pop-up box that appears after you copy your
program to the computer.
K L
140
Making Simple Robots, 2nd Edition
Make_Simple_Robots_interior_FIN.indd 140Make_Simple_Robots_interior_FIN.indd 140 4/26/22 1:56 PM4/26/22 1:56 PM
“Collapse Block.” The whole stack will shrink down to just the
purple “on [shake]” block with three dots inside. Click the arrow to
open up the whole stack again
(Figure
N
)
.
9. Now give the FiberBot even more personality by making it talk! Write
another stack of code that tells the micro:bit to listen for a voice or
sound, and then “answer” with random robot noises. To do all that, you
will program the micro:bit to:
Wait before it responds when it hears a loud noise, like a voice (so
the person has a chance to finish speaking).
Pick a random number.
Select which robot noise to make, based on what number it picks!
M
N
Chapter 4: Making Robots Likable 141
Make_Simple_Robots_interior_FIN.indd 141Make_Simple_Robots_interior_FIN.indd 141 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