const int buttonPin = 2; //dig.pin connect to switch
const int ledPin = 13; //pin connected to led
int buttonState = 0; //initial value of switch
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT); //set led pin as output
pinMode(buttonPin, INPUT); //set switch pin as input
}
void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin); //read input from pin 2
if (buttonState == HIGH) { //if switch pressed, set as HIGH
digitalWrite(ledPin, HIGH); //turn ON led
}
else {
digitalWrite(ledPin, LOW); //otherwise, OFF led
}
}