7 – Creepy Crawlies

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:
Tip: Click the Gear icon to open settings, click “Playback Speed”, and select “0.5x” or “0.25x” to slow down the video so its easier to follow along!
At about 1:15, it’s hard to tell which pieces are needed. Here they are.
At 1:48, they forgot to show putting these two green pieces at the ends.
At 2:46, instead of the mount on the front, put the distance sensor. It looks like a good mouth, too, don’t you think?
Put the sensor wire out the side and then over the top – not out the back – or it will get in the way.
At about minute 2:10, a step is missing. Be sure to use these small white pieces, not the longer ones.
Once the robot caterpillar is built, try making a WeDo program that does the same thing as this real computer program.
MOTOR.POWER= 8
REPEAT FOREVER:
     MOTOR.DIRECTION=BACKWARD
     MOTOR.TIME = 2
     MOTOR.DIRECTION=FORWARD
     MOTOR.TIME = 2
If you get stuck, click here for a hint!

Here’s a challenge 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