View Single Post
  #2   Spotlight this post!  
Unread 08-03-2007, 16:23
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: Code to Read the Binary Inputs on Analog Buttons

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

Last edited by kaszeta : 08-03-2007 at 17:21.
Reply With Quote