Beginner Error Question

Greetings all...I apologize if this is an easy question, but I appreciate the help in advance. Here is the code: else
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250);
}
}

The very last curly bracket is where I am getting the error, "expected declaration before '}' token

I tried your code, and it wouldn't even compile! My guess is the error is somewhere in the part you didn't post. Care to share your entire sketch? Please use the [code] tags ttho.

Yog1Girl:
Here is SOME OF :wink: the code

You probably need a "{" after the "else" to balance things. Difficult to say without all the code though.

 else
{ //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  digitalWrite(3, LOW);

int switchState = 0;

void setup() {
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);
delay(250);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250);
}
}

Else { maybe?

Silly me, the { was missing :-p

But now here is the new error:

Arduino: 1.8.5 (Mac OS X), Board: "Arduino/Genuino Uno"
Sketch uses 1220 bytes (3%) of program storage space. Maximum is 32256 bytes.
Global variables use 11 bytes (0%) of dynamic memory, leaving 2037 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "COM1": No such file or directory
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Unplug and restart ide

Tried that, still the same.

"Silly me, the { was missing :-p"

Use code formatter - CTRL_T - it will help you to find errors likes non-matching brackets.

Yog1Girl:
Tried that, still the same.

The error you are getting now, and a bunch of others I sometimes get, I put down to voodoo. Frequently, the IDE complains under circumstances which have not changed outwardly, with known good code, and it just randomly throws out errors. I put it down to us getting what we pay for, the IDE being free.

Eventually, after a few offs and ons, and switching off the anti virus (sometimes helps, not always) and even trying to compile the Bare Minimum (one thread somewhere says to try that, sometimes it works, not always) and standing on one leg the problems go away. At least until they come back in 5 minutes or 5 hours or 5 days.

Caveat emptor.

You are probably not connected to COM1. On my PC, the Arduino seems to prefer COM3. The way to tell is to look at the port list before you plug in the Arduino. Then restart the IDE and plug in the board. The correct COM port will be the one that was not there when you looked the first time.

On a Mac it is 100% certain that COM1 or COM3 is not the right port...

Select the right port under Tools > Port.
It should be something like cu.usbmodemXXX.

Ah, I have a Mac, and it was the port. Thank you all very much for your help!

OK another beginner: Worked my way through to line 27. Now I don't know where to go. On correct port. Used Auto Format and Fix encoding. i retyped the code three times. I think I have it as pictured in the book. Hooked up the board and tried loading several times. No luck. Ideas?

1 int switchState = 0;

2 void setup() {
3 pinMode(3,OUTPUT);
4 pinMode(4,OUTPUT);
5 pinMode(5,OUTPUT);
6 pinMode(2,INPUT);
7 }

8 void loop () {
9 switchState = digitalRead(2);
10 // this is a comment
}
11 if (switchState == low) {
12 // the button is not pressed
13 digitalWrite(3, HIGH); // green LED
14 digitalWrite(4, LOW); // red LED
15 digitalWrite(5, LOW); // yellow LED
16 }
17 else { // the button is pressed
18 digitalWrite(3, LOW); // green LED
19 digitalWrite(4, LOW); // red LED
20 digitalWrite(5, HIGH); // yellow LED
21 delay (250); // wait for a qurter second
22 // toggle the LEDs
23 digitalWrite (4, HIGH);
24 digitalWrite (5, LOW);
25 delay (250); // wait for a qurter second
26 }
27 } // go back to the beginning of the loop

LINE 27 ERROR

sketch_feb17a:4: error: expected unqualified-id before numeric constant
1 int switchState = 0;
^
sketch_feb17a:7: error: expected unqualified-id before numeric constant
2 void setup() {
^
sketch_feb17a:14: error: expected unqualified-id before numeric constant
8 void loop () {
^
sketch_feb17a:18: error: expected unqualified-id before numeric constant
11 if (switchState == low) {
^
sketch_feb17a:24: error: expected unqualified-id before numeric constant
17 else { // the button is pressed
^
sketch_feb17a:34: error: expected unqualified-id before numeric constant
27 } // go back to the beginning of the loop
^
sketch_feb17a:34: error: expected declaration before '}' token
27 } // go back to the beginning of the loop
^
exit status 1
expected unqualified-id before numeric constant

Have you seen any other examples, in C or C++, where people typed in line numbers?