Hardware Reference
In-Depth Information
▪ 22 kΩ resistor (see “Resistors” )
A variable resistor with three terminals
Figure 2-8 shows a simple variable resistor (trimpot) wired to the Bone. One end terminal
is wired to the ADC 1.8 V power supply on pin P9_32 , and the other end terminal is at-
tached to the ADC ground ( P9_34 ). The middle terminal is wired to one of the seven
analog-in ports ( P9_36 ).
Figure 2-8. Wiring a 10kΩ variable resistor (trimpot) to an ADC port
Example 2-5 shows the BoneScript code used to read the variable resistor. Add the code
to a file called analogIn.js and run it; then change the resistor and run it again. The
voltage read will change.
Example 2-5. Reading an analog voltage (analogIn.js)
#!/usr/bin/env node
var b = require ( 'bonescript' );
b . analogRead ( 'P9_36' , printStatus );
function printStatus ( x ) {
console . log ( 'x.value = ' + x . value . toFixed ( 3 ));
console . log ( 'x.err = ' + x . err );
}
Search WWH ::




Custom Search