Thread: limit switches
View Single Post
  #15   Spotlight this post!  
Unread 28-04-2005, 07:12
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: limit switches

Quote:
Originally Posted by Alan Anderson
If you have the switch wired properly, between SIG and GND, the digital input will read 1 when the switch is open, and 0 when the switch is closed.
Quote:
Originally Posted by workaphobia
Your input will be in the 0 state when the switch is pressed. This isn't a problem at all, just invert where you have tests for 1s and 0s.
Quote:
Originally Posted by stephenthe1
actually, limit switches are the opposite of that. They are normally 0, or true, then once pressed, turn to 1.
Quote:
Originally Posted by Workaphobia
Er, unless I'm severely mistaken, it's ==0 for when a digital input is grounded, ==1 for when it's not grounded, ==0 for an unpressed joystick button, and ==1 for a pressed joystick button.


I can never remember/am never sure which it is, so I setup #defines at the beginning of a include file I put all that general setting stuff in, then use that in my tests. IE:
PHP Code:
#define SWITCH_ON 1 /* Value switches give when on. */
#define SWITCH_OFF !SWITCH_ON

if(rc_switch_01 == SWITCH_ON)
{
    
// ...

That way, if I'm wrong, I have to change one value and my entire program changes to reflect it. Plus, it makes your logic (to some people) clearer.
__________________


Last edited by Ryan M. : 28-04-2005 at 10:10. Reason: Missed my closing code tag