Go Down

Topic: reading pins (Read 432 times) previous topic - next topic

Lubby

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? :(

drhex

#1
Jul 10, 2010, 12:04 am Last Edit: Jul 10, 2010, 12:06 am by drhex Reason: 1
Code: [Select]
boolean switchOpen(){
 [glow]return[/glow] digitalRead((switchPin) == HIGH);
}


- yet another reason Arduino shouldn't disable compiler warnings.

davekw7x

#2
Jul 10, 2010, 12:04 am Last Edit: Jul 10, 2010, 12:32 am by davekw7x Reason: 1
Quote
Any ideas?

Code: [Select]

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

Lubby

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

Thanks. ;D

Go Up