Go to Post Every mentor we lose is potentially dozens of students lost... - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Control System
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 08-03-2007, 16:17
Kingofl337's Avatar
Kingofl337 Kingofl337 is offline
You didn't see anything....
AKA: Adam
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 1998
Location: Manchester, NH
Posts: 861
Kingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond repute
Send a message via Yahoo to Kingofl337
Code to Read the Binary Inputs on Analog Buttons

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.

For Example:

1000 0000 = Button 1
0100 0000 = Button 2
0010 0000 = BUtton 3
0001 0000 = Button 4

The trouble is the last four digits are random and fluctuate greatly
depending on what mood the chicklet is in so sometimes

1000 0000 = Button 1
or
1000 0001 = Button 1
or
1000 0010 = Button 1

The problem is we really don't want to make 4 cases for every button.
So we just want to ignore them.
__________________
FIRST Team 501 PowerKnights - Mentor
FIRST Team 40 Checkmate - Mentor Alum
FIRST Team 146 Blue Lightning - Alumni

Last edited by Kingofl337 : 08-03-2007 at 16:26.
Reply With Quote
  #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
  #3   Spotlight this post!  
Unread 08-03-2007, 16:40
Kingofl337's Avatar
Kingofl337 Kingofl337 is offline
You didn't see anything....
AKA: Adam
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 1998
Location: Manchester, NH
Posts: 861
Kingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond repute
Send a message via Yahoo to Kingofl337
Re: Code to Read the Binary Inputs on Analog Buttons

Nice, never used that before
__________________
FIRST Team 501 PowerKnights - Mentor
FIRST Team 40 Checkmate - Mentor Alum
FIRST Team 146 Blue Lightning - Alumni
Reply With Quote
  #4   Spotlight this post!  
Unread 13-03-2007, 21:14
aegeon aegeon is offline
Registered User
FRC #0818
 
Join Date: Mar 2007
Location: Sterling Heights
Posts: 1
aegeon is an unknown quantity at this point
Re: Code to Read the Binary Inputs on Analog Buttons

now correct me if im wrong but isnt your use of the ? operator the same as the ! operator

im pretty sure that

p1_sw_5 = !(p1_aux&1<<7);
will do the same as
p1_sw_5=(p1_aux&1<<7)?0:1;

Last edited by aegeon : 14-03-2007 at 21:06.
Reply With Quote
  #5   Spotlight this post!  
Unread 13-03-2007, 21:35
tdlrali tdlrali is offline
Registered User
FRC #0469 (Las Guerrillas)
Team Role: Programmer
 
Join Date: Sep 2006
Rookie Year: 2006
Location: MI
Posts: 377
tdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud of
Re: Code to Read the Binary Inputs on Analog Buttons

the "(statement)?true:false" syntax is like an if statement in one line
if statement, then true, else false

in this case, however, it would do the same
Reply With Quote
  #6   Spotlight this post!  
Unread 14-03-2007, 11:01
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 aegeon View Post
now correct me if im wrong but isnt youre use of the ? operator the same as the ! operator
You are correct.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Analog Inputs!! brennerator Programming 7 11-02-2007 15:48
Analog Inputs bush Programming 5 13-03-2006 17:49
How do the Analog Inputs work? JBotAlan Electrical 3 07-01-2005 00:11
Failing analog inputs? Phasmatis568 Control System 5 22-01-2004 13:28
Analog Inputs 316_programer Technical Discussion 2 05-02-2002 05:53


All times are GMT -5. The time now is 20:27.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi