Blink using button. Acts as if Normaly Closed?

Arduino Due IDE 1.5.7 Windows 8

Just getting started with arduino and I thought I'd combine the blink and and button examples. When I set up the buttonState in the if statement I have to set it to LOW, instead of HIGH like in the example code, in order to get the light to blink while the button is pressed. It acts as if the button is Normally Closed. Shouldn't the inputs be LOW initially?

My Code:

const int led = 13; const int gnbtn = 52;

int buttonState = 0;

void setup() {

pinMode(led, OUTPUT); pinMode(gnbtn, INPUT);

}

void loop() {

buttonState = digitalRead(gnbtn);

if (buttonState == LOW){

digitalWrite(led, HIGH); delay(300); digitalWrite(led, LOW); delay(300); } else {

digitalWrite(led, LOW); }

}

How is the switch wired?

(please use code tags when posting code)

Pin 52 is wired to left button terminal and ground is wired to right button terminal. I know left and right are not the best terms to use but assume they are :P

beedoebeedoe: Pin 52 is wired to left button terminal and ground is wired to right button terminal. I know left and right are not the best terms to use but assume they are :P

you are grounding the pin with the press of the button; bringing it it LOW.

what would happen if you attached the 'right button terminal' to Vcc at 5V? You would send a HIGH signal to your pin.

but, you would need a resistor for that so take a look at this example

look at INPUT_PULLUP...

To add: pinMode(gnbtn, INPUT_PULLUP); // enable internal pullup resistor

Pin will now read HIGH unless button is pressed to connect it to Gnd.

Without the pullup, the pin can float and not reliably read high or low.