Chapter 5. Switches and Other Topics
The Switch Block
Switches allow the flow of a program to branch along one of two or more routes. The route taken depends on a preset condition. The condition may be the output from a sensor, or the value of a given variable (numeric, logic, or text). The program in Figure 5.1 shows a switch being controlled by the output of the light sensor. If the light intensity is less than 50, the switch routes the microcontrollers along the lower sequence beam. The sound block plays “dark.” If the intensity is greater than 50, the switch routes the microcontrollers along the upper beam and the sound block plays “light.” Either way, the microcontrollers eventually leave the switch by the single exit.