- :-

Topics Covered

  • Color Sensor
  • Repeat Loop Behavior
  • RepeatUntil Loop Behavior
  • Check Your Understanding:
    1. 1. True / False: With the simple maze program, the repeat(forever) command should have a semicolon
      at the end of it.
    2. True
      False
    3. 2. True / False: A loop repeats the commands inside of its curly brackets.
    4. True
      False
    5. 3. True / False: A repeat loop can be set to be run forever, for a certain amount of times, or to a sensor condition.
    6. True
      False
    Did You Know?

    Did you know?

    If/Else Statements vs. RepeatUntil Loops

    If conditional statements execute code immediately if the condition is met and skip to the next chuck of code if the condition is not met.

    If the condition in an if conditional statement is true, then the code within the curly braces directly below the if conditional statement is executed. Loops repeat commands until their condition is met. See the examples below.

    If the condition of the if conditional statement is false the program skips to the next section of code. In this example it will skip “else” and to the code within the curly braces after the else.

    When a repeatUntil's condition is false, the program will run the code within the if/else conditional statement until the condition is true.

    When the repeatUntil conditional in the conditional loop is satisfied (the condition is true) the program jumps out of the loop to the next line in the program.

    Color Sensor (Repeat Behaviors) - Mini Challenges

    Mini Challenge 1: Color Hunt

    Program the robot to make the appropriate decisions based upon the color of the color tiles on the challenge board.

    When the robot detects the color red, it should make a 90 degree left turn.
    When the robot detects the color blue, it should make a 135 degree right turn.
    When it detects the color green, it should stop.
    • Recreate the table below on any surface. Have the robot move from the start (1), then detect colors along the way. Each color will have the robot turn a certain number of degrees to navigate throughout the challenge.

    Mini Challenge PDF[ Color Hunt Challenge.pdf ]

    Mini Challenge 2: Recycle

    In this challenge, the robot should start on one end of the challenge table. To begin, the robot moves forward.

    If the rectangular object in front of it is detected to be green, the robot should move the object to the left to be recycled.

    If the rectangular object in front of the robot is detected to be red, the robot should move the object to the right.
    • Recreate the table below on any surface. Use objects that the robot can easily move and manipulate.

    Mini Challenge PDF[ Recycle Challenge.pdf ]