O'Reilly logo

Programming Lego Mindstorms NXT by Owen Bishop

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Figure 5.1. Demonstrating ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required