Hello All!
I am new to Arduino and I keep getting the same three error messages in my code. I am trying to have a green LED turn on when a button is not pressed and have two red LED's blink when it is pressed. Unfortunately, it keeps telling me the following:
2:29: error: expected unqualified-id before 'if'
if (switchState == Low) {
2:35: error: expected unqualified-id before 'else'
else {
2:45: error: expected declaration before '}' token
} //end of loop()
I have searched online for suggestions but I have not been able to find anything that looks like this. Below is the rest of my code. Please take a look and let me know what I can do to fix it. Thank you!
int switchState = 0;
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
switchState = digitalRead(2);
}
//if the button is not pressed
if (switchState == Low) {
digitalWrite(3, HIGH); // green LED on
digitalWrite(4, LOW); // red LED off
digitalWrite(5, LOW); // red LED off
}
//if the button is pressed
else {
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay (250); //wait a quarter second
//toggle the red LEDs
digitalWrite(4, HIGH);
digitatWrite(5, LOW);
delay (250);
} //end of else statement
} //end of loop()