Quote:
Originally Posted by Qbranch
Just as a reassurance, we are successfully using this on our OI panel this year.
-q
|
As have we, for many years. We don't use the pullup resistor approach - the ground doesn't appear in our method of wiring switches to analog input. I've never had a problem with this method.
Remember, on the OI, you don't need to have a ground connection for an analog input pot reading - on the joysticks, it's just five volts through the joystick axis pot straight to the analog input. We duplicate this method in wiring digital switches to our analog in's.
For devices such as rocker switches or 3-position toggle switches where only one state can be active at one time due to the mechanics of the device, wire two resistors of differing values (each less than 100K - say 10k and 80k - whatever - I like to pick them to have a distinct separation that can easily be tested for in the code) between the +5V and the different poles of the device. 10k on one pole, 80k on the other. Wire the common of the device to a single analog input.
When you actuate the switch, you connect 5V through either 10k or 80k into the analog input, resulting in a distinct numeric value for each position. Use if statements to test for ranges centered around these values and set binary variables accordingly:
Code:
//Wrist Rocker switch on button box
if ((wristrocker > 218) && (wristrocker < 240)) //Wrist Reverse/Up rocker is active
{
wristfwd_sw = 0;
wristrev_sw = 1;
}
else if ((wristrocker > 73) && (wristrocker < 95)) //Wrist Forward/Down rocker is active
{
wristfwd_sw = 1;
wristrev_sw = 0;
}
else
{
wristfwd_sw = 0;
wristrev_sw = 0;
}