Projects Book, Project 02 program error

Hi everyone,

My first program, copying out of the Projects Book. Why does it get an "expected unqualified-id before numeric constant" message at line 8? Is the rest of the code ok?

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); // blue LED
14 digitalWrite(4, LOW); // green LED
15 digitalWrite(5, LOW); // yellow LED
16 }
17 else { //the button is pressed
18 digitalWrite(3, LOW);
19 digitalWrite(4, LOW);
20 digitalWrite(5, HIGH);
21 delay(250); // wait for a quarter second
22 // toggle the LEDs
23 digitalWrite(4, HIGH);
24 digitalWrite(5, LOW);
25 delay(250); //wait for a quarter second
26 }
27 }

There, I think I fixed it. Got rid of the line numbers and spaces and tried to be consistent with indents. I thought that the line numbers in the book were necessary, guess not.

1 Like

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

You can format your indents by selecting TOOLS, then Auto Format
OR
press CTRL-T.

Tom.. :slight_smile:

1 Like