Hardware Reference
In-Depth Information
Figure 7-8: Bar graph decimal representations
As you discovered in Chapter 3, “Reading Analog Sensors,” the range of usable
values for the IR distance sensor is not the full 10-bit range. (I found that a max
value of around 500 worked for me, but your setup will probably differ.) Your
minimum might not be 0 either. It's best to test the range of your sensor and fill
in appropriate values. You can place all the bar graph decimal representations
in an array of nine values. By mapping the IR distance sensor (and constraining
it) from 0 to 500 down to 0 to 8, you can quickly and easily assign distances to
bar graph configurations. The code in Listing 7-3 shows this method in action.
Search WWH ::




Custom Search