Hi, I'm trying to wire up a big red arcade-style button with one Normally Open and one Normally Closed terminal to my Arduino but am unable to get any correct readings. (I followed the following thread as a model: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1215022988)
I connected the NO terminal of the button to a ground pin on the Arduino, and then the NC terminal to a regular pin (9). I then enabled the (supposed) internal pull-up resistor on pin 9. Theoretically, I thought this would make it return a 0 when the button is pushed down and a 1 when not. Instead, it always returns 1, regardless of whether or not the button is pushed down.
Here's my code, if it helps:
int inputPin = 9;
int buttonState;
int val;
void setup() {
pinMode(inputPin, INPUT);
digitalWrite(inputPin, HIGH);
Serial.begin(9600);
buttonState = digitalRead(inputPin); // store initial button state (should be high)
}
void loop() {
val = digitalRead(inputPin);
if (val != buttonState) {
if (val == LOW) {
Serial.println("Button - low");
} else {
Serial.println("Button - high");
}
}
buttonState = val;
}
Would anybody be able to tell me what I am doing wrong here?
Thanks in advance.