Pages: [1]   Go Down
Author Topic: reading pins  (Read 420 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm having issues with my input pin reads.  I have been using booleans but have also tried giving the direct 'digitalRead' statements as well.  My readings are inconsistent with the programing, or more likely the programing is off.

I am reading microswitches.  5vdc through 510ohm resistor when open.  0vdc when closed.  I have tried the input pins with and without pullups and pulldowns.

RE: booleans = a very simplified version:

with input pin set to 4, and output 13.

void loop(){

if(switchClosed()){
Serial.println("Switch Closed");
}

if(switchOpen()){
Serial.println("Swith Open");
}
} // end of loop

boolean switchOpen(){
   digitalRead((switchPin) == HIGH)
}

boolean switchOpen(){
   digitalRead((switchPin) == LOW)
}

if for example I make the pin low, nothing happens.  if I make the pin high both register even through the switchOpen is only supposed to read low.  When I have used the (!switchClosed()) or (!switchOpen()) they never register.  Things only seem to show up when the ! is not used and when the pin is high.  The problem is that i can only get one reading for some reason.  I do need both for the application I have.

I have also try hooking the input pin to ground and then to the 5vdc on board to see if I can register a change.  Also tried the pullups.  Is my programming off?  I have tried on alternative pins in the chance the one used was burnt out for some reason.  

Any ideas? smiley-sad
Logged

Knivsta,Sweden
Offline Offline
Sr. Member
****
Karma: 0
Posts: 274
Low level's cool
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
boolean switchOpen(){
  [glow]return[/glow] digitalRead((switchPin) == HIGH);
}

- yet another reason Arduino shouldn't disable compiler warnings.
« Last Edit: July 09, 2010, 05:06:34 pm by drhex » Logged

Left Coast, USA
Offline Offline
Sr. Member
****
Karma: 7
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Any ideas?
Code:
boolean switchOpen(){
  return (digitalRead[glow]([/glow]switchPin[glow])[/glow] == HIGH);
}

boolean switchClosed(){
  return (digitalRead[glow]([/glow]switchPin[glow])[/glow] == LOW);
}

Quote
- yet another reason Arduino shouldn't disable compiler warnings.
Yeah, and I'm still waiting for Atmel to implement the "Branch on Bug" machine instruction that I told them about last April  (Patent Applied For).  If they would only do that, the CPU could catch any program errors that the compiler missed.


Regards,

Dave
« Last Edit: July 09, 2010, 05:32:05 pm by davekw7x » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is like gold for me.  I've spent hours trying to work through the problems!

Thanks. ;D
Logged

Pages: [1]   Go Up
Jump to: