I have a code which i feel doesnt have any errors ...but when i compile this is

i have a problem compiling my program i have uploaded the program and the pictures of the error when compiling!

anujith_me_ankush_robot_bluetooth_ino.ino (3.56 KB)

Untitled3.png

Untitled4.png

Untitled5.png

Untitled6.png

Untitled7.png

Untitled8.png

Defines should not have Semicolons on them at the end.

define TRIG_PIN 2*;*

define ECHO_PIN 3*;*

define MAX_DISTANCE 100*;*

BTW, there is nothing in your .INO file that you uploaded, it is empty or corrupted.

You should get in the habit of using 'const int' in place of #define for integer constants:

const int TRIG_PIN = 2;
const int ECHO_PIN = 3;
const int MAX_DISTANCE = 100; // In cm

johnwasser: You should get in the habit of using 'const int' in place of #define for integer constants:

Why?

aarg: Why?

It results in less bizarre error messages when you get something wrong. :)

johnwasser: It results in less bizarre error messages when you get something wrong. :)

I never get anything wrong. :) But, doesn't declaring with const allow better type checking than #define? Hmmm....

Fix the errors, one at a time, starting with the first one.

aarg: Why?

Because it's a good idea. Pffft.

vishnu2001:
i have a problem compiling my program i have uploaded the program and the pictures of the error when compiling!

<14 attachments>

Have you heard of .zip files?

Look, no-one is going to download 14 files, one by one, just to reproduce your problem. (Unless they are very bored). Zip the whole project up and attach one file.

i feel everything is correct!!! :cold_sweat: :cold_sweat: :roll_eyes: ::slight_smile: :sob:

Untitled3.png

Untitled4.png

Untitled5.png

Untitled6.png

Untitled7.png

Untitled8.png

and the pictures of the error when compiling!

Copy and paste the error messages. Don't take screen shots of them.

One thing that isn't correct, is the way you're showing us your code. Please cut and paste it into your post, using code tags. Nobody can possibly wade through all those images and help you. Not for free.

[quote author=Nick Gammon link=msg=2151367 date=1427007937] Because it's a good idea. Pffft. [/quote]

Well, I can see that #define lacks any data typing. Is there any other reason? I'm genuinely curious. "Good idea" is pretty vague. If memory serves, I've often seen things like:

#define PI 3.1415927

in fairly respectable code.

A perfect example of the difficult to troubleshoot problem macros create... http://forum.arduino.cc/index.php?topic=93451.0

A problem that is easily avoided by using typed constants.

this is the error code::
this time the code in comments

sketch_mar21a:13: error: expected `)' before ';' token
sketch_mar21a:13: error: expected unqualified-id before ',' token
sketch_mar21a:13: error: expected unqualified-id before numeric constant
sketch_mar21a:13: error: expected unqualified-id before ',' token
sketch_mar21a:13: error: expected unqualified-id before numeric constant
sketch_mar21a:13: error: expected unqualified-id before ')' token
sketch_mar21a:15: error: 'Servo' does not name a type
sketch_mar21a:16: error: 'Servo' does not name a type
sketch_mar21a:17: error: 'Servo' does not name a type
sketch_mar21a:18: error: 'Servo' does not name a type
sketch_mar21a:21: error: 'IRrecv' does not name a type
sketch_mar21a:29: error: 'decode_results' does not name a type
sketch_mar21a.cpp: In function 'void setup()':
sketch_mar21a:33: error: 'irrecv' was not declared in this scope
sketch_mar21a:34: error: 'servo1' was not declared in this scope
sketch_mar21a:36: error: 'servo2' was not declared in this scope
sketch_mar21a:38: error: 'servo3' was not declared in this scope
sketch_mar21a:40: error: 'servo4' was not declared in this scope
sketch_mar21a.cpp: In function 'void loop()':
sketch_mar21a:46: error: 'irrecv' was not declared in this scope
sketch_mar21a:46: error: 'results' was not declared in this scope
sketch_mar21a:49: error: expected primary-expression before ')' token
sketch_mar21a:53: error: expected primary-expression before ')' token
sketch_mar21a:57: error: expected primary-expression before ')' token
sketch_mar21a:62: error: expected primary-expression before ')' token
sketch_mar21a:67: error: expected `}' before 'else'
sketch_mar21a:71: error: 'else' without a previous 'if'
sketch_mar21a.cpp: At global scope:
sketch_mar21a:75: error: expected declaration before '}' token
Exception in thread "Thread-5" java.lang.NullPointerException
at processing.app.syntax.TokenMarker.addToken(TokenMarker.java:299)
at processing.app.syntax.TokenMarker.markTokens(TokenMarker.java:100)
at processing.app.syntax.JEditTextArea._offsetToX(JEditTextArea.java:550)
at processing.app.syntax.JEditTextArea.scrollTo(JEditTextArea.java:464)
at processing.app.syntax.JEditTextArea.scrollToCaret(JEditTextArea.java:429)
at processing.app.syntax.JEditTextArea.select(JEditTextArea.java:1205)
at processing.app.Editor.statusError(Editor.java:2574)
at processing.app.Editor$DefaultRunHandler.run(Editor.java:1867)
at java.lang.Thread.run(Thread.java:619)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


and this is my code>>


#include <NewPing.h>
#include<Servo.h>
#include<IRremote.h>

#define TRIG_PIN 2;
#define ECHO_PIN 3;
#define MAX_DISTANCE 100;
#define led1 9
#define led2 12
#define led3 11
#define led4 10


NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

Servo servo1;
Servo servo2;  //right
Servo servo3;  //back left
Servo servo4;  //back right


IRrecv irrecv(REC_PIN);

int RECV_PIN = 13;
unsigned int time;
int fdistance;
int bdistance;
int rdistance;
int ldistance;
decode_results results;

void setup() {
 Serial.begin(9600);
irrecv.enableIRIn();
servo1.attach(4);
servo1.write(90);
servo2.attach(5);
servo2.write(90);
servo3.attach(6);
servo3.write(90);
servo4.attach(7);
servo4.write(90);
}


void loop() {
 if (irrecv.decode(&results)) {
   Serial.println(results.value,HEX);
   irrecv.resume();
   if(results.value == ) {
     moveForward();
     delay(500); 
   }
 else if(results.value == ) {
  moveBackward();
  delay(500); 
 }
  else if(results.value == ) {
    moveRight();
    delay(500); 
  }
  
   else if(results.value == ) {
    moveLeft();
   delay(500); 
   }
   delay(5000);
   else {
     bluetooth();
   }
   
   else {
     obstaclemode();
   }
 }
}

void bluetooth() {
 if (Serial.available()>0)  //if the serial is available and is > 0 the....
{
 int data = Serial.read();  //save the signal in the variable data
 switch(data)  // i dont know what it is????? maybe a syntax
 {
   case 'w' : moveForward(); break;  //if the letter w is received by the bluetooth module....then move forward
   case 's' : moveBackward(); break;  // same thing ..but for s
   case 'a' : moveLeft(); break; // same thing ..but for a
   case 'd' : moveRight(); break; // same thing ..but for d
   default : break;
 }
}
delay(50);
}

void obstaclemode() {
 scan();
 fDistance = distance;                  //Set that distance to the front distance
 if(fDistance < triggerDistance){       //If there is something closer than 30cm in front of us
   moveBackward();    //Move Backward for a second
   leddance();
   delay(1000); 
   moveRight();    //Turn Right for half a second
   leed();
   delay(500);
   moveStop();                          //Stop
   scan();                              //Take a reading 
   rDistance = distance;                //Store that to the distance on the right side
   moveLeft();
   leeed();
   delay(1000);                         //Turn left for a second
   moveStop();                          //Stop
   scan();                              //Take a reading
   lDistance = distance;                //Store that to the distance on the left side
   if(lDistance < rDistance){           //If the distance on the left is smaller than that of the right
     moveRight();      //Move right for a second
     leed();
     delay(1000);
     moveForward();                     //Then move forward
     ld();
     delay(1000);
   }
   else{
     moveForward();                     //If the left side is larger than the right side move forward
     ld();
     delay(1000);
   }
 }
 else{
   moveForward();                       //If there is nothing infront of the robot move forward
   ld();
   delay(1000);
 }
}

void scan(){
 time = sonar.ping();                  //Send out a ping and store the time it took for it to come back 
 distance = time / US_ROUNDTRIP_CM;    //Convert that time into a distance
 if(distance == 0){                    //If no ping was recieved
   distance = 100;                     //Set the distance to max
 }
 delay(10);
}

void moveBackward(){
  servo1.write(0);
 servo2.write(0);
 servo3.write(0);
 servo4.write(0);
}

void moveForward(){
 servo1.write(180);
 servo2.write(180);
 servo3.write(180);
 servo4.write(180);
 
 
}

void moveRight(){
servo1.write(180);
servo2.write(0);
servo3.write(180);
servo4.write(0);
}

void moveLeft(){
 servo1.write(0);
 servo2.write(180);
 servo3.write(0);
 servo4.write(180);
 
 
}

void moveStop(){
 servo1.write(90);
 servo2.write(90);
 servo3.write(90);
 servo4.write(90);
 
}
void leddance() {
 digitalWrite(led1,HIGH);
 digitalWrite(led1,LOW);
 digitalWrite(led2,HIGH);
 digitalWrite(led2,LOW);
 digitalWrite(led3,HIGH);
 digitalWrite(led3,LOW);
 digitalWrite(led4,HIGH);
 digitalWrite(led4,LOW);
}
void ld() {
 digitalWrite(led1,HIGH);
 digitalWrite(led1,LOW);
 digitalWrite(led2,HIGH);
 digitalWrite(led2,LOW);
 digitalWrite(led3,HIGH);
 digitalWrite(led3,LOW);
 digitalWrite(led4,HIGH);
 digitalWrite(led4,LOW);
}
void leed(){
digitalWrite(led1,HIGH);
 digitalWrite(led1,LOW);
 digitalWrite(led2,HIGH);
 digitalWrite(led2,LOW);
 digitalWrite(led3,HIGH);
 digitalWrite(led3,LOW);
 digitalWrite(led4,HIGH);
 digitalWrite(led4,LOW);
 digitalWrite(led3,HIGH);
 digitalWrite(led3,LOW);
 digitalWrite(led4,HIGH);
 digitalWrite(led4,LOW);
}
 void leeed() {
   digitalWrite(led1,HIGH);
 digitalWrite(led1,LOW);
 digitalWrite(led2,HIGH);
 digitalWrite(led2,LOW);
 digitalWrite(led3,HIGH);
 digitalWrite(led3,LOW);
 digitalWrite(led4,HIGH);
 digitalWrite(led4,LOW);
 digitalWrite(led3,HIGH);
 digitalWrite(led3,LOW);
 digitalWrite(led4,HIGH);
 digitalWrite(led4,LOW);
 }

johnwasser: You should get in the habit of using 'const int' in place of #define for integer constants:

const int TRIG_PIN = 2;
const int ECHO_PIN = 3;
const int MAX_DISTANCE = 100; // In cm

Even better, don't use an int when a byte will do.

aarg: Well, I can see that #define lacks any data typing. Is there any other reason? I'm genuinely curious. "Good idea" is pretty vague. If memory serves, I've often seen things like:

#define PI 3.1415927

in fairly respectable code.

Well, for one thing, the problems at the start of this thread:

#define MAX_DISTANCE 100;

You need to be cautious you don't have the trailing semicolon.

Remember that #define just does a textual substitution, not a semantic one. If an error is generated you get all sorts of weird messages.

    else if(results.value == ) {

== what?

Code tags please.

You didn’t like the answers the first time around? You still haven’t fixed the issue mentioned in the first reply.

@vishnu2001: Will you stop reporting the replies to moderator? Just reply to the thread don't "report" the thread. That's twice in half an hour.