Skip to main content

Introduction

One of your tasks on the mission is to secure the planet for mankind - learn how to speed up your programs to get our robot to patrol the planet surface.

  1. Make sure your robot is setup in the same way as the previous section, with the magnets still attached!
    • Make sure your robot is setup in the same way as the previous section, with the magnets still attached!

  2. For the rest of this lesson, we need to be able to make the robot turn accurately. Build the program in the picture, and make sure to use the wait 100 milliseconds block instead of the wait 1 second block.
    • For the rest of this lesson, we need to be able to make the robot turn accurately.

    • Build the program in the picture, and make sure to use the wait 100 milliseconds block instead of the wait 1 second block.

    • You can find it in the control menu - this block allows us to adjust the wait time by amounts smaller than 1 second!

    • There are 1000 milliseconds in 1 second - adjust the number until your robot turns by exactly 90 degrees. Don't forget to get the challenge checked off when you've done it!

  3. Now you can turn by 90 degrees, write a program that makes your robot move in a square! It should like something like the example in the picture but your 'wait' commands will be different.
    • Now you can turn by 90 degrees, write a program that makes your robot move in a square!

    • It should like something like the example in the picture but your 'wait' commands will be different.

    • If you think about it, you only need to reverse 1 motor and then set it to forwards again to change direction - one motor can be going forward all the time.

    • Also, you don't necessarily need to stop after turning - just set the motor going in reverse to go forward again!

  4. Making that last program took a while - and the robot was just doing the same things over and over again.
    • Making that last program took a while - and the robot was just doing the same things over and over again.

    • Say we wanted to drive in a square 10 times - that would take ages to program!

    • Driving in a square was doing the same thing 4 times:

    • Drive forward

    • Wait

    • Turn

    • Wait

    • We can use a loop to get the computer to repeat these steps for us!

  5. One of the most useful loops is the Do Forever loop
    • One of the most useful loops is the Do Forever loop

    • Anything inside this loop is just repeated forever!

    • Let's use this to make our robot move in a square forever.

    • Drag in a do forever loop from the basic menu, and put some blocks inside it that make your robot drive forward and then turn 90 degrees

    • Upload the code to your robot - it should move in a square forever!

  6. What if we don't want to move in a square forever? Luckily, there are other types of loops we can use that can do things more cleverly.
    • What if we don't want to move in a square forever?

    • Luckily, there are other types of loops we can use that can do things more cleverly.

    • Replace your do forever loop with a do _ times loop, and change it so it only repeats 4 times (look in the Control menu)

    • Now your robot should move in a square once, then stop!

  7. Now your robot can drive in a square using a loop, let's change the code so it will drive in a figure of 8. Have a look at the picture if you don't know what a figure of 8 is.
    • Now your robot can drive in a square using a loop, let's change the code so it will drive in a figure of 8.

    • Have a look at the picture if you don't know what a figure of 8 is.

    • Try to split the shape up into 2 sections, and use a do _ times loop to reduce the length of your sequence.

Finish Line

Tech Camp

Member since: 10/03/2012

119 Guides authored

Team

Tech Camp Staff Member of Tech Camp Staff

6 Members

140 Guides authored