int switchState = 0;
// declares a variable named switchstate with an initial value of 0 (off) and type integer
void setup() {
// put your setup code here, to run once:
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
switchState = digitalRead(2);
//will read the voltage on pin 2 and store it digitally ("LOW" or "HIGH") in variable switchstate
if (switchState == LOW) {
//button not pressed
delay (250);
digitalWrite(3, HIGH); //green LED
delay (250);
digitalWrite(4, HIGH); //red LED 1
delay (250);
digitalWrite(4, LOW); //red LED 1
delay (250);
digitalWrite(5, LOW); //red LED 2
//will write digitally on the respective pin, aka will send voltage (HIGH) or not (LOW)
}
else {//button pressed
digitalWrite(3, LOW); //green LED
digitalWrite(4, LOW); //red LED 1
digitalWrite(5, HIGH); //red LED 2
//delay(10000);
}
} //restart of the loop