View Single Post
  #5   Spotlight this post!  
Unread 08-03-2008, 09:18
Travis Hoffman's Avatar Unsung FIRST Hero
Travis Hoffman Travis Hoffman is offline
O-H
FRC #0048 (Delphi E.L.I.T.E.)
Team Role: Engineer
 
Join Date: Sep 2001
Rookie Year: 2001
Location: Warren, Ohio USA
Posts: 4,047
Travis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond reputeTravis Hoffman has a reputation beyond repute
Re: Using Analog Inputs as Digital (on the OI)

Quote:
Originally Posted by Qbranch View Post
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; 
}
__________________

Travis Hoffman, Enginerd, FRC Team 48 Delphi E.L.I.T.E.
Encouraging Learning in Technology and Engineering - www.delphielite.com
NEOFRA - Northeast Ohio FIRST Robotics Alliance - www.neofra.com
NEOFRA / Delphi E.L.I.T.E. FLL Regional Partner