Conditional Statement (Switch block) Pro Preview

Today we will focus on another block which will allow our robots to make decisions. This block is in the Flow Control palette and is called “Switch”.

To access the full video please subscribe to FLLCasts.com

Subscribe

  • #892
  • 12 Dec 2017

Take the block and put it in the program:

This block will form branches in our program. We will set a condition which can be either met or not, either true or false. When the condition is met, one sequence of blocks will be executed, and when not – another one. In our case, when the condition is met, the blocks located in the upper half (marked with a tick) will be executed.

If the condition is not met, the blocks located in the lower half (marked with an X) will be executed.

Let’s now take a closer look at the block when the ultrasonic sensor sets the condition. From the dropdown menu we choose "Ultrasonic Sensor > Compare > Distance Centimeters".

We should first set up the number of the port where the sensor is connected. Then, we should set the condition and finally put the blocks which should be executed in the two different cases.

 

For example, if we want the robot to go forward if the nearest object is more than 50 cm away and backward if not, the program should look like this:

Try out the program. Notice that the check is immediate and unlike orange wait blocks, there is no waiting here.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Instructors Remote Training
  • 136
  • 280:11
  • 156
Image for Switch
  • 7
  • 0
  • 7
  • 3d_rotation 1
Image for Level B1. "Spy gadgets". Robotics with LEGO
  • 30
  • 7:30
  • 108
Image for Lesson 2 - Switch
  • 2
  • 3
  • 3
  • 3d_rotation 1
Image for Robotics with LEGO - Level 1.5 - Spy games
  • 56
  • 12:47
  • 135