Go to Post FIRST always talks about grandmothers and making them proud. So FIRST---you made my grandmother proud. - Collin Fultz [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-01-2008, 08:55
Spencer E.'s Avatar
Spencer E. Spencer E. is offline
Android junkie
FRC #1305 (NNSRI Ice3 (cubed))
Team Role: Alumni
 
Join Date: Apr 2005
Rookie Year: 2004
Location: Ontario, Canada
Posts: 91
Spencer E. has a spectacular aura aboutSpencer E. has a spectacular aura about
Send a message via MSN to Spencer E.
Selecting bits from an analog input

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. Is there a simple way to do this or will I just have to do some math and figure out which output is being pressed by removing 128, 64, 32 and 16 from the output? Thanks in advance!
__________________
  #2   Spotlight this post!  
Unread 13-01-2008, 09:03
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: Selecting bits from an analog input

Quote:
Originally Posted by Spencer E. View Post
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).
  #3   Spotlight this post!  
Unread 13-01-2008, 09:06
Spencer E.'s Avatar
Spencer E. Spencer E. is offline
Android junkie
FRC #1305 (NNSRI Ice3 (cubed))
Team Role: Alumni
 
Join Date: Apr 2005
Rookie Year: 2004
Location: Ontario, Canada
Posts: 91
Spencer E. has a spectacular aura aboutSpencer E. has a spectacular aura about
Send a message via MSN to Spencer E.
Re: Selecting bits from an analog input

Thanks so much!
__________________
Closed Thread


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
Analog Input Errors... Tach'ko Electrical 1 11-01-2008 11:37
HELP: analog input Tottanka Programming 19 18-02-2007 19:27
Programming Analog Input from 2004 Controller Danny Diaz Programming 8 30-01-2007 22:44
Analog Input Trouble Matt Krass Programming 10 20-01-2005 21:09
DC Motor current to an Analog Input junkyarddawg Motors 43 04-04-2002 15:53


All times are GMT -5. The time now is 09:16.

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