Go Down

Topic: [Solved] Error after compiling (Read 650 times) previous topic - next topic

Arduinofan

Nov 23, 2009, 12:11 am Last Edit: Nov 23, 2009, 10:12 am by Stevos Reason: 1
I don't know if I'm at the appropiate section, but I think this is the closest it get. ::)

I was building my RFID-lock and everything ran smoothly, but.....

After I got my script up and running I started cleaning my script (remove unwanted spaces, clean empty lines etc.).  I noticed that there has occured an error during compiling. The annoying this is that I can't figure out what I'm missing. I'm afraid I erased an essential element but I just can't find it ....  :-[ I've been trying all afternoon now and I know the answer is simple. I just can't figure it out :'(

The error I keep getting tells me the following:
Code: [Select]
error: expected constructor, destructor, or type conversion before '=' token
I tried looking in google but it didn't helped me one bit >:(

So basicly, the code was fine until I cleaned it up a bit :-[
Here it is:
Code: [Select]
#include <Servo.h>
#define TAG_LEN 12

Servo myservo;  // create servo object to control a servo

char tag[12] = {'*', '*', '*', '*', '*', '*', '*', '*', '*', '*'};      // First tag
char tag_2[12] = {'*', '*', '*', '*', '*', '*', '*', '*', '*', '*'};     // Second tag
char code[12];
int bytesread = 0;
int ledPin = 11; // Connect LED to pin 13
int ledPin2 = 13;
int rfidPin = 2; // RFID enable pin connected to digital pin 2
int val = 0;

// -------AUDIO------

int speakerPin = 11;

int length = 15; // the number of notes
char notes[] = "cdefgabC ";            // Melody for correct tag
char notes_2[] = "ccc ";                 // Melody for incorrect tag
int beats[] = {1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };         // beat length
int tempo = 50;                                                        // speed of the melody


void playTone(int tone, int duration) {
 for (long i = 0; i < duration * 1000L; i += tone * 2) {
   digitalWrite(speakerPin, HIGH);
   delayMicroseconds(tone);
   digitalWrite(speakerPin, LOW);
   delayMicroseconds(tone);
 }
}

void playNote(char note, int duration) {
 char names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
 int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};

 // play the tone corresponding to the note name

 for (int i = 0; i < 8; i++) {
   if (names[i] == note) {
     playTone(tones[i], duration);
   }
 }
}

// -------AUDIO------

void setup() {
 pinMode(speakerPin, OUTPUT);
 Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
 pinMode(rfidPin,OUTPUT);   // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
 pinMode(ledPin,OUTPUT); // Set ledPin to output

 digitalWrite(rfidPin, LOW); // Activate the RFID reader

 digitalWrite(ledPin, HIGH);
 delay(100);
 digitalWrite(ledPin, LOW);
 delay(100);
 digitalWrite(ledPin, HIGH);
 delay(100);
 digitalWrite(ledPin, LOW);

 myservo.attach(9);  // attaches the servo on pin 2 to the servo object
 myservo.write(0);   // set servo position
}

void loop() {
 // ---------------------------- READING TAG -----------------------------\\    
 if(Serial.available() > 0) {          // if data available from reader
   if((val = Serial.read()) == 10) {   // check for header
     bytesread = 0;
     while(bytesread<10) {              // read 10 digit code
       if( Serial.available() > 0) {
         val = Serial.read();
         if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
           break;                       // stop reading
         }
         code[bytesread] = val;         // add the digit
         bytesread++;                   // ready to read next digit
       }
     }
     if(bytesread >= 10) {              // if 10 digit read is complete

       // ---------------------------- END READING TAG -----------------------------\\

       // ----------------- FIRST TAG ---------------\\
       if(strcmp(code, tag) == 0) {
         digitalWrite(2, HIGH);
         sound1();
         servo1();
         blink();
         delay(2000);
         digitalWrite(2, LOW);


       }

       // -------------- END FIRST TAG ---------------\\


       //-----------------------2ND TAG -------------\\
       if(strcmp(code, tag_2) == 0) {
         digitalWrite(2, HIGH);        // deactivate reading
         sound1();                     // make a melody (see below)
         servo1();                     // unlock (see below)
         blink();                      // light flashes (see below)
         delay(2000);                    // wait before second reading
         digitalWrite(2, LOW);           // activate the device again
       }
       //----------------- END 2ND TAG -------------\\



       //------------- if tag is wrong -------------\\

       else {
         digitalWrite(2, HIGH);      // deactivate reading
         sound2();                   // make a melody (see below)
         blink2();                   // light flashes (see below)
         delay(1000);                   // wait before second reading
         digitalWrite(2, LOW);          // activate the device again

       }

       //------------- END if tag is wrong -------------\\

     }
     bytesread = 0;                    // clear memory
     delay(500);                // wait for a second
   }
 }
}
//--------------------- END RFID reading and validation ---------------\\
void blink() {
 
 digitalWrite(ledPin2, HIGH);
 delay(100);
 digitalWrite(ledPin2, LOW);
 delay(100);
 digitalWrite(ledPin2, HIGH);
 delay(100);
 digitalWrite(ledPin2, LOW);
 delay(100);
 digitalWrite(ledPin2, HIGH);
 delay(100);
 digitalWrite(ledPin2, LOW);
 delay(100);
 digitalWrite(ledPin2, HIGH);
 delay(100);

 digitalWrite(ledPin2, LOW);
}

void blink2() {
 digitalWrite(ledPin2, HIGH);
 digitalWrite(ledPin2, LOW);

}

// ------------AUDIO--------------
void sound1(){

 for (int i = 0; i < length; i++) {
   if (notes[i] == ' ') {
     delay(beats[i] * tempo);  
   }
   else {
     playNote(notes[i], beats[i] * tempo);
   }

   delay(tempo / 2);

 }  

}
// ------------AUDIO--------------

// ------------AUDIO 2--------------
void sound2(){

 for (int i = 0; i < length; i++) {
   if (notes_2[i] == ' ') {
     delay(beats[i] * tempo);
   }
   else {
     playNote(notes_2[i], beats[i] * tempo);
   }

   delay(tempo / 2);

 }

}
// ------------END AUDIO 2--------------


void servo1(){
 myservo.write(100);
 delay(2000);
 myservo.write(0);      

}


I was hoping you guys (and girls ;)) could help me out a bit :-/

PaulS

What this message is really saying is that the compiler didn't recognize something before the = on the line that is causing the error.

I was able to get your code to compile by removing all the "\\" at the ends of some of the comments.

Arduinofan

Ok, so what you're saying is that the "\\" disturbs the comment and acts like a part of the script that needs to be excecuted? I didn't know that. Man, do I feel stupid :-/

Arduinofan

Thanks Paul!

It's working like train ;)

PaulS

The "\\" certainly shouldn't cause problems. They are part of a comment.

However, removing them allows the compiler to compile the code. So, clearly they DO cause problems. The simple solution is "Don't do that!".

AWOL

#5
Nov 23, 2009, 10:29 am Last Edit: Nov 23, 2009, 10:37 am by AWOL Reason: 1
The '\' is the line-continuation character. You're making more things part of the comment than you want to.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Quote
The '\' is the line-continuation character.

In basic, maybe. There ain't no such thing in C, C++, or C#.

AWOL

#7
Nov 23, 2009, 10:37 am Last Edit: Nov 23, 2009, 10:46 am by AWOL Reason: 1
Quote
There ain't no such thing in C, C++, or C#.

Hah!
Code: [Select]
// I promise that the next line won't error \
#error

// Convinced?

void setup ()
{
}

void loop ()
{
}
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up