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.