First code progamming first trouble :/

Hi Everybody,

As the main title says, I'm approaching the Arduino and Electronics in general for my first time.

I bought a Starter kit and I start...;), On my second project I found a trouble, I follow the book to create the Spaceship interface.

I read and then copy the code from the book to the program, but I still receive an error when I hit Verify button on the program.

I posted here the code I wrote, I check it several times, but it continues to give me this error:

steve1:15: error: expected unqualified-id before numeric constant

When I hit Verify button on the program, it put on evidence this symbol } on the 4th line of the code.

If I erase the } symbol it put on evidence the following line so: 1 int switchState = 0;

Can somebody help me?

Thank you in advance guys and girls!

Steve.

void setup(){
}
void loop(){
}
1 int switchState = 0;

2 void setup(){
3 pinMode(3,OUTPUT);
4 pinMode(4,OUTPUT);
5 pinMode(5,OUTPUT);
6 pinMode(2,INPUT);
}
8 void loop(){
9 switchState = digitalRead(2);
10 // Quando il programma legge il doppio slash// non legge la linea, tutto quello che resta su questa linea non viene letto dal programma e ci permette di lasciare messaggi per spiegare il funzionamento!!!!

11 if (switchState == LOW) {
12 // il bottone non è premuto

13 digitalWrite(3, HIGH); // LED VERDE
14 digitalWrite(4, LOW); // LED ROSSO
15 digitalWrite(5, LOW); //LED ROSSO
16 }

17 else { // il pulsante viene premuto
18 digitalWrite(3, LOW);
19 digitalWrite(4, LOW);
20 digitalWrite(5, HIGH);

21 delay(250); // aspetta un quarto di secondo
22 // lampeggiano i led?
23 digitalWrite(4, HIGH);
24 digitalWrite(5, LOW);
25 delay(250); // aspetta 1/4 secondi

}

} // torna all'inizio del loop

Lose the line numbers.

int switchState = 0;

void setup()
{
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(2,INPUT);
}
    
void loop()
{
  switchState = digitalRead(2);
  // Quando il programma legge il doppio slash// non legge la linea, tutto quello che resta su questa linea non viene letto dal programma e ci permette di lasciare messaggi per spiegare il funzionamento!!!!
      
  if (switchState == LOW) {
    // il bottone non è premuto
    digitalWrite(3, HIGH); // LED VERDE
    digitalWrite(4, LOW); // LED ROSSO
    digitalWrite(5, LOW); //LED ROSSO
  }
  else { // il pulsante viene premuto
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
       
    delay(250); // aspetta un quarto di secondo
    // lampeggiano i led?
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
    delay(250); // aspetta 1/4 secondi
  }
}

dbkill3r84:
I read and then copy the code from the book to the program, but I still receive an error when I hit Verify button on the program.

The C language uses no line numbers as the BASIC programming language did in the 80s of the last century.

So leave out the line numbering while typing program listings.

And setup() and loop() are duplicate in your code, they must appear once in every arduino sketch.

 int switchState = 0;

 void setup(){
 pinMode(3,OUTPUT);
 pinMode(4,OUTPUT);
 pinMode(5,OUTPUT);
 pinMode(2,INPUT);
}
 void loop(){
 switchState = digitalRead(2);
 // Quando il programma legge il doppio slash// non legge la linea, tutto quello che resta su questa linea non viene letto dal programma e ci permette di lasciare messaggi per spiegare il funzionamento!!!!
  
 if (switchState == LOW) {
 // il bottone non è premuto
    
 digitalWrite(3, HIGH); // LED VERDE
 digitalWrite(4, LOW); // LED ROSSO
 digitalWrite(5, LOW); //LED ROSSO
 }
  
 else { // il pulsante viene premuto
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
 digitalWrite(5, HIGH);
    
 delay(250); // aspetta un quarto di secondo
 // lampeggiano i led?
 digitalWrite(4, HIGH);
 digitalWrite(5, LOW);
 delay(250); // aspetta 1/4 secondi

   }

} // torna all'inizio del loop

Is there no CD with your starter set that contains all the program listings?
Some place in the Internet where you can download them?
Or copy-and-paste from a file?
You really have to type them in manually?

If this is the official Arduino Starter Kit then a lot of the code is under File -> Examples -> 10. Starter Kit.

Ops, I copy exactly the same types of the book and on the book ther is line numbers!!!

In the starter kit there's no CD, there's a book, I copy that on the Arduino program, which I downloaded from the website.

Anyway yes I type it manually because if I copy one correct or if I select it from a menu I learn only to do that but I don't learn what all this commands means, instead I read the explanations and then without the book I try to compose my code, then, of course, I look at the book if I made mistakes...

Anyway I thank you all for your precious answers! I solve the problemS!

Thank you!

Have a nice day!