VoltageReader

Reading digital inputs for buttons, switches, and the like is fine, but sometimes you may want to read analog inputs as well. The VoltageReader in Figure 3-4 shows how this can be done.

Architecture of VoltageReader

Figure 3-4. Architecture of VoltageReader

The complete code is given in Example 3-2. It polls a potentiometer every three seconds and prints the raw value and the corresponding voltage value to the debug output.

Note

If you develop on Mac OS X or Linux, the debug output can be sent over a serial line instead of USB. For more information, please see the Mono forum at http://forums.netduino.com/.

Example 3-2. VoltageReader

using System.Threading; using Microsoft.SPOT; ...

Get Getting Started with the Internet of Things now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.