const int buttonPin = 4; // Pin connected to pushbutton
const int ledPin = 12; // Pin connected to LED
int buttonState; // Give pushbutton a value
void setup()
{
pinMode(ledPin, OUTPUT); // Set LED pin as output
pinMode(buttonPin, INPUT); // Set pushbutton pin as input
}
void loop() { buttonState = digitalRead(buttonPin); // Read input from pin 4
if(buttonState == LOW) {
// If pushbutton is pressed, set as low
digitalWrite(ledPin, HIGH); // Turn on LED
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
else
{
digitalWrite(ledPin, LOW); // Otherwise, turn off LED
}
}