Quote:
Originally Posted by Spencer E.
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).