I have copied this code from the Arduino Projects Book. I have gone over it many times and it seems to be identical to the code in the book. Yet i get the error message with line 8 highlighted. Can anyone tell me what I have done wrong? Also, can the error message be translated into something I might understand. Thanks in advance.
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 on
14 digitalWrite(4,LOW); // red off
15 digitalWrite(5,LOW); // red off
16 }
17 else { // button is pressed
18 digitalWrite(3,LOW);
19 digitalWrite(4,LOW);
20 digitalWrite(5,HIGH); tttt y y
21 delay(250); // wait 1/4 second
22 //toggle the LEDs
23 digitalWrite(4,HIGH);
24 digitalWrite(5,LOW);
25 delay(250); // wait 1/4 second
26 }
27 } // go back to the beginning of the loop
Use the IDE autoformat tool (ctrl-t or Tools, Auto Format).
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 on
digitalWrite(4, LOW); // red off
digitalWrite(5, LOW); // red off
}
else // button is pressed
{
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250); // wait 1/4 second
//toggle the LEDs
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); // wait 1/4 second
}
} // go back to the beginning of the loop
Thank you. Don,t know how that tttt y y slipped in, it wasn't there when I tested things. But the line numbers, they were the problem. They are gone now and all is good.