I've been looking over and over the code and can't see anything wrong but there has got to be. I would appreciate if someone could help me out. I'm trying a simple repeating loop. The code is below,
Thanks in advance.
Error Message reads:
"Arduino: 1.6.6 (Windows 7), Board: "Arduino/Genuino Uno"
_1:26: error: expected unqualified-id before 'else'
else { // the button is pressed
^
_1:39: error: expected declaration before '}' token
} // go back to the beginning of the loop
^
exit status 1
expected unqualified-id before 'else' "
Code:
int switchState = 0;
void setup() {
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop() {
switchState = digitalRead(2);
// this is a comment
if (switchState == LOW) {
// the button is not pressed
}
digitalWrite(3, HIGH); // green LED
digitalWrite(4, LOW); // red LED
digitalWrite(5, LOW); // red LED
}
else { // the button is pressed
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250); // wait for a quarter second
// toggle the LEDs
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); // wait for quarter second
}
} // go back to the beginning of the loop