![]() |
The Switch block is a container that can contain two or more sequences of programming blocks. Each sequence is called a Case. A test at the beginning of the Switch determines which Case will run. Only one Case will run each time the Switch is executed. |
• | A Switch does not wait for a sensor data value or data wire to reach a certain value. The test is run as soon as the Switch block starts, and one of the Cases is chosen and run immediately after the test. |
• | In the program above, you can press the Touch Sensor before the test (or even before the program starts) and hold it in during the test, to make sure the Switch executes the True Case. Try seeing how long you can wait before pressing the sensor and still have the robot say “Yes”. |
• | You can leave any Case in a Switch blank if you don’t want the robot to do anything in that situation. Try removing the two blocks from the False Case in the program above and see what happens. |
Mode | Use | See |
---|---|---|
Brick Buttons – Measure - Brick Buttons | Choose between two or more Cases depending on which Brick Button is pressed. | Using the Brick Buttons |
Brick Buttons – Compare - Brick Buttons | Choose between two Cases depending on whether one of the selected Brick Buttons is Pressed, Released, or Bumped. | Using the Brick Buttons |
Color Sensor – Measure - Color | Choose between two or more Cases depending on which color is detected. | Using the Color Sensor |
Color Sensor – Compare - Color | Choose between two Cases depending on whether or not one of the selected colors is detected | Using the Color Sensor |
Infrared Sensor – Measure - Remote | Choose from two or more Cases depending on which button(s) are pressed on the IR Beacon. | Using the Infrared Sensor Remote Mode |
Infrared Sensor – Compare - Remote | Choose between two Cases depending on whether a specified button on the IR Beacon is pressed (or whether one of a set of specified buttons is pressed). | Using the Infrared Sensor Remote Mode |
Touch Sensor - Compare - State | Choose between two Cases depending on whether the Touch Sensor is Pressed or not, Released or not, or Bumped or not. | Using the Touch Sensor |
Ultrasonic Sensor – Compare - Presence/Listen | Choose between two Cases based on whether an ultrasonic signal is detected in “listen only” mode. | Using the Ultrasonic Sensor |
Messaging | Choose between two Cases based on a message value. | Messaging |