improving RedOrBlue

You can use the Range block to improve the RedOrBlue program from Chapter 5. The original program uses the Light Sensor or the Color Sensor in Light Sensor mode and assumes that all objects are either red or blue. In this section, you’ll change the program to eliminate this assumption, using the Range block to more accurately assign the color (red or blue) based on the Light Sensor reading.

The improvements made in this section can also be made to the RedOrBlueCount program. I’m using the simpler RedOrBlue program here to make it easier to concentrate on the use of the Range block. The original RedOrBlue program (shown in Figure 14-36) uses a Switch block to decide which color an object is based on the Light Sensor reading. ...

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.