There are more than 20,000 different species of caterpillars on earth, but this zoo is lucky to have the only caterpillar that is a robot! Here’s how to make the caterpillar:
Once the robot caterpillar is built, try making a WeDo program that does the same thing as this real computer program.
See the envelope at the end of the first line of blocks? It remembers the value that’s on its tag, the number zero. It sends that number zero to all the other programming blocks, where you see the envelope arriving through the mail slot. The second line starts when it gets a message of the number zero. The last line does NOT start, because it only starts when it gets a message of the number 1.
When the second line finishes, it sends out a number 1. The last line starts gets that message. The number one matches its starting number, so it starts. At the end of that line, it sends a 0, and back we go to the second line, which starts when it gets a number zero.
Programmers call that a VARIABLE. They use these a lot! Think of video games you’ve played. The game remembers your health, your score, things you’ve picked up in the game, and lots of other things.
Here’s what that looks like in code:
MOTOR.POWER= 8
DO 3 TIMES:
MOTOR.DIRECTION=BACKWARD
MOTOR.TIME = 2
MOTOR.DIRECTION=FORWARD
MOTOR.TIME = 2
VARIABLE = 0
DO FOREVER:
IF VARIABLE = 0 THEN DO:
SCREEN.PRINT "I'M HUNGRY"
WHILE SENSOR.INPUT IS NOT CLOSE:
WAIT
IF SENSOR.INPUT IS CLOSE:
SCREEN.PRINT "YUM!"
VARIABLE = 1
IF VARIABLE = 1 THEN DO 3 TIMES:
MOTOR.DIRECTION=BACKWARD
MOTOR.TIME = 2
MOTOR.DIRECTION=FORWARD
MOTOR.TIME = 2
VARIABLE = 0