Hello all,
I'm a beginner, and I've read several threads in other forums about my error and I just can't figure it out.
Details:
- I'm running an Arduino UNO board on a PC
- I'm trying to complete Project #2 in the "Arduino Starter Kit" (aka "Spaceship" project)
- Specifically, I'm trying to turn different LEDs on by pressing the button
- The LEDs work with the code below, but nothing happens when I press the button.
Troubleshooting I've done so far:
- I know the button is working based on a previous project
- I made sure that the curly braces are all paired
- The error I'm getting: "expected unqualified-id before 'else'" seems to be related to line 21 (where "else" shows up), but I can't see anything in previous lines that should cause a problem.
Here is my code:
int switchState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop(){
switchState = digitalRead(2);
if (switchState == LOW)
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
else {
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
I'd really appreciate any guidance. I'm new to this, so please be kind ![]()
All the best,
Louis