"error expected unqualified-id before numeric constant" boolean

Got this error message when trying to compiling: "error expected unqualified-id before numeric constant" at the line starting with "boolean".

I already looked at other similar posts but it doesn't fix the bug. Thank you for any suggestion.

The first part of the code is:

#include 
#include 

const int irReceivePin = 2;   // pin connected to IR detector output
IRrecv irrecv(irReceivePin);    // create the IR library
decode_results results;         // IR data goes here

const int rightMotorPin = 9;  // Connected to right servo
const int leftMotorPin = 10;  // Connected to left servo

Servo rightServo;
Servo leftServo;

int rightSpeed = 90;
int leftSpeed = 90;

long keyCode = 0;
boolean DEBUG = true; // set to true if you want to display the Debug output

void setup()
{
  if(DEBUG){
    Serial.begin(9600);
  }

(deleted)

Thank you, here's the whole code.

#include 
#include 

const int irReceivePin = 2;   // pin connected to IR detector output
IRrecv irrecv(irReceivePin);    // create the IR library
decode_results results;         // IR data goes here

const int rightMotorPin = 9;  // Connected to right servo
const int leftMotorPin = 10;  // Connected to left servo

Servo rightServo;
Servo leftServo;

int rightSpeed = 90;
int leftSpeed = 90;

long keyCode = 0;
// set to true if you want to display the Debug output
boolean DEBUG = true; 

void setup()
{
  if(DEBUG){
    Serial.begin(9600);
  }

  irrecv.enableIRIn();              // Start the IR receiver

  leftServo.attach(9);
  rightServo.attach(10);
  
  pinMode(rightMotorPin, OUTPUT);
  pinMode(leftMotorPin, OUTPUT);
}

void loop() {
  if( irrecv.decode(&results) )

  {
    keyCode=results.value;
    if(keyCode != -1)
    {
      switch (keyCode){
        case 50174055:  // Replace this code with the one from your remote!
        Serial.println("Forward");
        leftSpeed-=1;  // Opposite values propel the wheels forward
        rightSpeed+=1; 
        break;
        
        case 50182215:  // Replace this code with the one from your remote!
        Serial.println("Backward");
        leftSpeed+=1;  // Opposite values propel the wheels backward
        rightSpeed-=1; 
        break; 
        
        case 50168955:  // Replace this code with the one from your remote!
        Serial.println("Stop");
        leftSpeed=90;  // A value of 90 stops the servos from turning
        rightSpeed=90; 
        break; 

        case 50152125:  // Replace this code with the one from your remote!
        Serial.println("Turn Left"); // Wheels move in opposite directions
        leftSpeed-=1;
        rightSpeed-=1;  
        break; 
        
        case 50135805:  // Replace this code with the one from your remote!
        Serial.println("Turn Right");  // Wheels move in opposite directions
        leftSpeed+=1;
        rightSpeed+=1;
        break; 
        
        case 50139885:  // Replace this code with the one from your remote!
        Serial.println("TURBO!!");  // need to move left servo to go right
        leftSpeed=leftSpeed-50;
        rightSpeed=rightSpeed+50;
        break; 

      }
      
     if(DEBUG){
      Serial.println(keyCode);
      showReceivedData();
      Serial.print(leftSpeed);
      Serial.print(", ");
      Serial.println(rightSpeed);
     }
     
    }
    irrecv.resume(); // Receive the next value
  }

  updateMotors();
  delay(10);
}

void showReceivedData()
{
  if (results.decode_type == UNKNOWN)
  {
    Serial.println("-Could not decode message");
  }
  else
  {
    if (results.decode_type == NEC) {
      Serial.print("- decoded NEC: ");
    }
    else if (results.decode_type == SONY) {
      Serial.print("- decoded SONY: ");
    }
    else if (results.decode_type == RC5) {
      Serial.print("- decoded RC5: ");
    }
    else if (results.decode_type == RC6) {
      Serial.print("- decoded RC6: ");
    }
    Serial.print("Value = ");
    Serial.println( results.value, DEC);
  }
}

void updateMotors(){
  leftServo.write(leftSpeed);
  rightServo.write(rightSpeed);
}

roberto03: Thank you, here's the whole code.

When I compile that, I get:

Binary sketch size: 6,886 bytes (of a 30,720 byte maximum)

Ok, I try to compile it again....

Unfortunately, I keep getting this error message after the code already posted above:

remote_test:19: error: expected unqualified-id before numeric constant

about the line:

boolean DEBUG = true;

Any help would be very appreciated.

Any help would be very appreciated.

So would some details. Like which board you are compiling for. Like which version of the IDE you are using.

PaulS: So would some details. Like which board you are compiling for. Like which version of the IDE you are using.

Board: Arduino UNO IDE: 1.0.5-r2

Thanks...

I am going to guess that there is another DEBUG defined somewhere. Change all your "DEBUG" to "Debug" which is more consistent with style anyway.

In file included from DEBUGTest.ino:4:0:
D:\Work\Arduino\libraries\IRremote/IRremote.h:124:16: error: expected unqualified-id before numeric constant
 #define DEBUG  0
                ^
DEBUGTest.ino:21:9: note: in expansion of macro 'DEBUG'

KeithRB: I am going to guess that there is another DEBUG defined somewhere. Change all your "DEBUG" to "Debug" which is more consistent with style anyway.

Unfortunately, no other "DEBUG" defined elsewhere...

roberto03: Unfortunately, no other "DEBUG" defined elsewhere...

See my previous post. It is defined in IRemote.h line 124.

You know, roberto03, we have been doing this a few years, so we have a pretty good idea about things to try. Also, do not discount the fact that variables should not have names in all-caps, just for this kind of reason.

Welcome to the world of namespace pollution.

Also, do not discount the fact that variables should not have names in all-caps, just for this kind of reason.

DEBUG is not a variable. It is a name created by a #define statement.

By convention, #define names SHOULD be all caps, to make it clear in the rest of the code that it is a name that will be replaced by the preprocessor.

Using the first thing that pops into ones head when creating a #define statement is what gets people into trouble. If that name is so obvious, clearly it will have been equally obvious to every other Tom, Dick or Harry that is developing a library.

That is why ALL of my code that has #define statements has my initials in the name portion.

Great, it works now, thank you all. I changed all the DEBUG to Debug.

Exactly PaulS, his "boolean DEBUG = true" should have been "boolean debug = true" and this whole mess would have been avoided.

Exactly PaulS, his "boolean DEBUG = true" should have been "boolean debug = true" and this whole mess would have been avoided.

The convention indicates that the name SHOULD be DEBUG. But, common sense says that DEBUG is likely to be used elsewhere. I would have used PJS_DEBUG (and hoped that no other developer with the initials PJS had also defined a debug variable the same way).

I think you are confused. The collision was because he created his own boolean variable named DEBUG. I said that according to convention, he should have called it Debug. If he would have created his own #define, your convention comes into play.

I think you are confused.

Not confused. Just not paying attention. Sorry about that.