const int ledPin = 13;
const int buttonPin = 2;
int buttonState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}