Go to Post You can sometimes step outside the box if you have properly thought through the question. - Jim Zondag [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 23-03-2004, 19:50
Kevin Karan's Avatar
Kevin Karan Kevin Karan is offline
Linux Guy
AKA: maxdamage
None #0174 (Arctic Warriors)
Team Role: Alumni
 
Join Date: Jan 2003
Location: Liverpool, NY
Posts: 141
Kevin Karan will become famous soon enoughKevin Karan will become famous soon enough
Send a message via AIM to Kevin Karan
digital input question...

Alright, feeling stupid. I know that the digial inputs give wierd junk since they are char variables. So what bit do I read and how. Thanks
__________________
It isnt ALWAYS the programmers falt!
2004: Buckeye team website award
2002: Rutgers semi-finalists
2001: National semi-finalists
2001: Rutgers semi-finalists
1998: Manchester Rookie All-Star Award
  #2   Spotlight this post!  
Unread 23-03-2004, 20:21
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: digital input question...

?

If you just want to tell if it is HIGH or LOW, you can do a check if it is 1 or 0. If for some reason you have to actually access the bits, experiment. I'm not sure if the chip is big- or little-endie.
__________________

  #3   Spotlight this post!  
Unread 23-03-2004, 20:25
Kevin Karan's Avatar
Kevin Karan Kevin Karan is offline
Linux Guy
AKA: maxdamage
None #0174 (Arctic Warriors)
Team Role: Alumni
 
Join Date: Jan 2003
Location: Liverpool, NY
Posts: 141
Kevin Karan will become famous soon enoughKevin Karan will become famous soon enough
Send a message via AIM to Kevin Karan
Re: digital input question...

The digital inputs are given as a char, but only one of the bits are actualy accurate, but I dont know what one. I know there is a post on this forum about it, but I cannot find it. AND, i cant remember how to get the value of a specific bit under c, is it var:1 or is it var&1
__________________
It isnt ALWAYS the programmers falt!
2004: Buckeye team website award
2002: Rutgers semi-finalists
2001: National semi-finalists
2001: Rutgers semi-finalists
1998: Manchester Rookie All-Star Award
  #4   Spotlight this post!  
Unread 23-03-2004, 21:27
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: digital input question...

the digital inputs on the RC are already defined in the code for you - they can only have a value of 1 or 0

all you need to do is look at the right variable

rc_dig_in01 is digital input one on the RC

so you can do stuff like

if (rc_dig_in01 ==1) variableXYZ=123;

if (rc_dig_in14 ==0) variableQRS=127;

what else do you want to do with them?
  #5   Spotlight this post!  
Unread 24-03-2004, 05:57
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: digital input question...

Quote:
Originally Posted by KenWittlief
the digital inputs on the RC are already defined in the code for you - they can only have a value of 1 or 0

all you need to do is look at the right variable

rc_dig_in01 is digital input one on the RC

so you can do stuff like

if (rc_dig_in01 ==1) variableXYZ=123;

if (rc_dig_in14 ==0) variableQRS=127;

what else do you want to do with them?
Looking back at my old post, I meant that, but I see how you didn't get it. You can't access a certain bit in a variable in an actual function. The first syntax you stecified can be used in a struct like this:

Code:
stuct bitVariable
{
int bit0:1;
int bit1:1;
int bit2:1;
int bit3:1;
// ...
};
Basically, tht gives each of the variables inside it one bit of the int. (at least, I think I got that right... ) Like Ken said though, you can just read the variable directly.
__________________

  #6   Spotlight this post!  
Unread 24-03-2004, 10:38
10intheCrunch's Avatar
10intheCrunch 10intheCrunch is offline
Who's John V-Neun?
AKA: Alex Baxter
None #0254 (Cheesy Poofs)
Team Role: College Student
 
Join Date: Feb 2004
Rookie Year: 2004
Location: San Jose, CA
Posts: 129
10intheCrunch is a jewel in the rough10intheCrunch is a jewel in the rough10intheCrunch is a jewel in the rough10intheCrunch is a jewel in the rough
Send a message via AIM to 10intheCrunch
Re: digital input question...

I'm pretty sure you can, if they are set up in a struct together. Say:

if(SomeStructbits.bit0) blah;

If you only want to see the first bit of any variable, though, use modulus.

if(someVar % 2) morestufftodo;

If you aren't familiar with modulus, it gives the remainder of dividing by the number you mod by, ie modding by 2 gives you one or zero depending on if the number is even or odd (or rather, if the first bit is 1 or 0).

Good luck.
__________________
~Alex Baxter
Programming, Arms operation, Team 254
  #7   Spotlight this post!  
Unread 24-03-2004, 10:50
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: digital input question...

If you want the 2 least significant bits, wouldn't it make more sense to do:
Code:
if(someVar & 3) evenmorestufftodo;
?
  #8   Spotlight this post!  
Unread 08-04-2004, 14:35
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,567
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: digital input question...

Quote:
Originally Posted by Astronouth7303
If you want the 2 least significant bits, wouldn't it make more sense to do:
Code:
if(someVar & 3) evenmorestufftodo;
?
That is what I would do, becasue the modulus operator is often slow (of course depending on the microprocessor). I haven't checked on the PIC, but if you ever want to move your code to a different platform, it's best to write for the lowest common denominator.

Sorry for bringing this thread up from the dead.
  #9   Spotlight this post!  
Unread 11-04-2004, 22:42
Kevin Karan's Avatar
Kevin Karan Kevin Karan is offline
Linux Guy
AKA: maxdamage
None #0174 (Arctic Warriors)
Team Role: Alumni
 
Join Date: Jan 2003
Location: Liverpool, NY
Posts: 141
Kevin Karan will become famous soon enoughKevin Karan will become famous soon enough
Send a message via AIM to Kevin Karan
Re: digital input question...

sorry for not being at all active on my threads lately... at buckeye I came up with something that worked well, though I cant remember it...
__________________
It isnt ALWAYS the programmers falt!
2004: Buckeye team website award
2002: Rutgers semi-finalists
2001: National semi-finalists
2001: Rutgers semi-finalists
1998: Manchester Rookie All-Star Award
  #10   Spotlight this post!  
Unread 12-04-2004, 07:34
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: digital input question...

I HATE that!
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
counting digital input CharlieWilken Programming 9 22-03-2004 19:56
Digital In Question Tom Bottiglieri Control System 5 02-03-2004 17:09
Question about input pins. Tom Bottiglieri Programming 3 15-02-2004 15:12
How do u hook up the digital input to the sensor's wires Fares Technical Discussion 2 14-02-2003 16:41
Robot Digital Input Mike Norton Technical Discussion 5 16-01-2003 14:31


All times are GMT -5. The time now is 02:54.

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