View Single Post
  #2   Spotlight this post!  
Unread 13-01-2008, 09:03
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Re: Selecting bits from an analog input

Quote:
Originally Posted by Spencer E. View Post
Hey everyone, we are going to be using the USB chicklet and for buttons 5-8 it uses 4 bits from the AUX port on the joystick but I can't figure out how to select the bits from the actual output.
There are several posts here on that if you search, but the easiest thing to do is use the bitwise AND operator. I also recommend writing a function that translates the AUX port to some global variables:

Code:
void Buttons(void)
{
   p1_sw_5=p1_sw_6=p1_sw_7=p1_sw_8=1;
   p1_sw_5=(p1_aux&1<<7)?0:1;
   p1_sw_6=(p1_aux&1<<6)?0:1;
   p1_sw_7=(p1_aux&1<<5)?0:1;
   p1_sw_8=(p1_aux&1<<4)?0:1;
}
where p1_sw_* are global variables.

(I wrote this to demonstrate the ?: operator to some students, you can also invert the logic test instead).