int buttonPin = 12;
int ledPin = 9;
void setup() {
// put your setup code here, to run once:
pinMode(buttonPin, INPUT); // set push button pin toreceive the signal to determine the state of LED
pinMode(ledPin, OUTPUT); // led pin will output
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(buttonPin) == HIGH){ // digital read obtains state of pin
digitalWrite(ledPin, LOW); // if button pin receives 5V signal (button is not pressed), turn off LED
}else{
digitalWrite(ledPin, HIGH); // button is pressed, signal transferred to GND --> turn on LED
}
}