- :-

Topics Covered

  • Loop with Sensor Control
  • Lesson Links

    Check Your Understanding:
    1. 1. When the Loop is set to use the Ultrasonic Sensor as shown below, what "condition" will cause it to let Program Flow pass (instead of keeping it in the loop)?

    2. The touch sensor is in a pressed state when the robot starts running the program.
      There is no object in front of the robot.
      An object placed 35 cm away from the Ultrasonic Sensor.
      An object placed 10 cm away from the Ultrasoinic Sensor.
    3. 2. What is the correct type of Repeat Loop to use if you want it to be controlled by a sensor?
    4. Repeat Forever
      A Repeat Block with Count Control
      A Repeat Until Block
      Any Repeat Block types will work
    5. 3. When does a repeatUntil Loop check the sensor?
    6. Continuously while inside the Loop
      At the beginning and end of the Loop only
      At the end of the Loop only
      At the end of every block within the Loop
    Try It!
    Try it! 1

    Repeat Until Touch Sensor

    Set the Loop's mode to Touch Sensor instead of Ultrasonic Sensor. Make sure the arm is raised on the robot.

    Run the program and try to get the robot to stop! Try it!

    What happens?
    The robot will check the Touch Sensor instead of the Ultrasonic Sensor at the beginning of the Loop to see whether it will send Flow in or leave the Loop.

    If the Touch Sensor is being pressed in at the time the Loop begins, the robot will stop! If not, it will move forward and backward as intended until the Touch Sensor is pressed.
    Mini Challenge

    Mini Challenge 1: Square Dance 3

    Facing obstacles is a very common problem a robot faces. You can use loops to anticipate the presence of an obstacle and stop the robot before it hits the object.
    • Use the same setting used in Square Dance 1 from the previous lesson ("Looped Movement").
    • Make your robot run laps around the box until it encounters an obstacle in its way. The obstacle will be placed so that it is visible to the robot immediately after it turns. See the diagram below to see where the obstacles should be placed.

    Start from the program you wrote from the previous mini-challenges, Square Dance 1 and Square Dance 2. You can create the program for this challenge by making a change just to the loop!

    + hint