Quote:
Originally Posted by Kingofl337
Does anyone have example code on how to read the binary digits from the OIs analog inputs? According to Mike only the first 4 binary digits are used to determine buttons being pressed.
|
The important thing is to use the bitwise AND function in C (&). That's what it's designed for.
Make a set of global variables, and a function that you call every time through the loop that sets these variables from the OI state.
Something like this should work (and I've gotta love any chance I have to legitimately use C' ?: trinary operator) :
Code:
int p1_sw_5,p1_sw_6,p1_sw_7,p1_sw_8; // Virtual buttons
void Buttons(void)
{
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;
}