Page 59 - The Unofficial Guide to Lego Mindstorms Robots
P. 59
48
The Light Sensor
Working with the light sensor can be a little tricky. As measured by the RCX, the light sensor outputs a value from 0 (dark) to
100 (bright). However, the signal generated by the sensor has some noise in it, which means the value jumps around
unpredictably. To use a light sensor effectively, then, you need to figure out what the interesting values are and how to respond
to them.
Testing Light Sensor Values
The easiest way to figure out what values your light sensor is generating is to use the RCX's View button. Press View
repeatedly until a little arrow appears under the input with the sensor. The RCX's screen should show the value of the sensor.
You can place Trusty so the light sensor is over the line, and then observe the value. Now see what values you get when Trusty
is off the line.
You should also try the green area of the Test Pad, and try all the measurements with the room both dark and light. This should
g ive you a good feel for the values that are important.
The View button only works if the input is configured to measure a light sensor. To have the input configured correctly, you'll
either have to run a program that sets it up or use the Test Panel, in the RCX Code section of the RIS software. Click on the
appropriate input until the light sensor appears. Then click on the Get Sensor Values button to get the current readings.
The choice of 35 and 40 in Trusty's program is based on my measurements; you may want to adjust these values for your
specific conditions.
Don't expect to get the same readings from two different light sensors, even under the sam e conditions with the same RCX.
Always test the values before you use them in a program.
The Light Sensor Watcher
What's going on with that sensor watcher in Figure 3-3? It's actually two sensor watchers rolled into one. The following
pseudocode shows how it works:
if the sensor value is in the range from 0 to 35 (but wasn't previously),
execute the "dark" commands
if the sensor value is in the range from 40 to 100 (but wasn't previously),
execute the "bright" commands