View Single Post
  #3   Spotlight this post!  
Unread 18-02-2008, 11:36
jacobhurwitz jacobhurwitz is offline
Registered User
FRC #0449 (Blair Robot Project)
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2007
Location: Maryland
Posts: 45
jacobhurwitz has a spectacular aura aboutjacobhurwitz has a spectacular aura aboutjacobhurwitz has a spectacular aura about
Re: joystick and extra buttons

Quote:
Originally Posted by Roger View Post
I don't know offhand the precidence of which does what first. I am assuming it is ((p3_aux & 1) << 7), not (p3_aux & (1 << 7)), but looking again I can't tell and I don't remember.
The bitshift operator has higher precedence than the binary and operator. So, it would be (p3_aux & (1<<7)).

What does this mean? Digital inputs are either 0 or 1. This would be like p1_sw_trig or something. It is 0 if it's not pressed and 1 if it is. An analog input can go from 0 to 255. An example of this is p1_x, which varies depending on where the joystick is.

p3_aux is an analog input, but not in the sense of p1_x. p3_aux is a combination of 8 digital inputs. The right-most bit refers to one switch, the next bit to another, etc. So p3_aux&1<<7 says, "is the seventh bit from the right true?" (It's actually the eighth bit, because we use zero-based counting here. p3_aux&1<<0 gives you the rightmost, etc.)

Does this make sense?