the switch block

The Switch block (shown in Figure 6-1) lets your program make a decision about which blocks to run. This type of structure is called a conditional because the program flow changes based on some condition. The Switch block uses the condition to choose from two or more groups of blocks, giving a program the ability to make a decision and react to the data read by the robot’s sensors. For example, the RedOrBlue program uses the reading from the Light Sensor for the test condition to decide which Sound block to run.

configuration panel

Figure 6-2 shows the Configuration Panel for the Switch block used in the RedOrBlue program. The three items on the left, Control, Sensor, and Display, affect the Switch block directly. The configuration ...

Get The Art of LEGO MINDSTORMS NXT-G Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.