Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[51] i got error as nmm.c(14):error c129:missing ';' before 'panmotor'

Status
Not open for further replies.

siddanagouda

Newbie level 6
Newbie level 6
Joined
Oct 2, 2014
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
hubli
Visit site
Activity points
81
my program is:
#include <reg51.h> //include Servo library

const int RForward = 0;
const int RBackward = 180;
const int LForward = 180;
const int LBackward = 0;

const int RNeutral = 90;
const int LNeutral = 90; //constants for motor speed
const int pingPin = 7;
const int irPin = 0;//Sharp infrared sensor pin
const int dangerThresh = 10; //threshold for obstacles (in cm)
int leftDistance, rightDistance; //distances on either side
Servo panMotor;
Servo leftMotor;
Servo rightMotor; //declare motors
long duration; //time it takes to recieve PING))) signal

void setup()
{ rightMotor.attach(11);
leftMotor.attach(10);
panMotor.attach(6); //attach motors to proper pins
panMotor.write(90); //set PING))) pan to center
}

void loop()
{
int distanceFwd = ping();
if (distanceFwd>dangerThresh) //if path is clear
{
leftMotor.write(LForward);
rightMotor.write(RForward); //move forward
}
else //if path is blocked
{
leftMotor.write(LNeutral);
rightMotor.write(RNeutral);
panMotor.write(0);
delay(500);
rightDistance = ping(); //scan to the right
delay(500);
panMotor.write(180);
delay(700);
leftDistance = ping(); //scan to the left
delay(500);
panMotor.write(90); //return to center
delay(100);
compareDistance();
}
}

void compareDistance()
{
if (leftDistance>rightDistance) //if left is less obstructed
{
leftMotor.write(LBackward);
rightMotor.write(RForward); //turn left
delay(500);
}
else if (rightDistance>leftDistance) //if right is less obstructed
{
leftMotor.write(LForward);
rightMotor.write(RBackward); //turn right
delay(500);
}
else //if they are equally obstructed
{
leftMotor.write(LForward);
rightMotor.write(RBackward); //turn 180 degrees
delay(1000);
}
}

long ping()
{
// Send out PING))) signal pulse
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

//Get duration it takes to receive echo
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

//Convert duration into distance
return duration / 29 / 2;
}
 

No types declared in or union!!!
"
Servo panMotor;
Servo leftMotor;
Servo rightMotor; //declare motors
"

Is a INT, CHAR, CONST, etc ???

Which compiler used (Arduino???)???
 
Last edited:

Where did you get that code from. It seems you are mixing 8051 and Arduino code.
 

I found this code on Instructables!!!

This is a How To Make an Obstacle Avoiding Arduino Robot!!!

"
Code:
/*MAEP 2.0 Navigation 
by Noah Moroze, aka GeneralGeek 
This code has been released under a Attribution-NonCommercial-ShareAlike license, more info at http://creativecommons.org/licenses/ 
PING))) code by David A. Mellis and Tom Igoe http://www.arduino.cc/en/Tutorial/Ping 
*/ 
#include <Servo.h>//include Servo library

const int RForward = 0; 
const int RBackward = 180; 
const int LForward = 0; 
const int LBackward = 180; 
const int RNeutral = 90; 
const int LNeutral = 90; //constants for motor speed 
const int trigpin = 7; 
const int echopin = 3; 
const int dangerThresh = 10; //threshold for obstacles (in cm) 
int leftDistance, rightDistance; //distances on either side 
Servo panMotor; 
Servo leftMotor; 
Servo rightMotor; //declare motors 
long duration; //time it takes to recieve PING))) signal 

void setup() 
{ 
rightMotor.attach(11); 
leftMotor.attach(10); 
panMotor.attach(6); //attach motors to proper pins 
panMotor.write(90); //set PING))) pan to center 
} 

void loop() 
{ 
int distanceFwd = ping(); 
if (distanceFwd>dangerThresh) //if path is clear 
{ 
leftMotor.write(LForward); 
rightMotor.write(RForward); //move forward 
} 
else //if path is blocked 
{ 
leftMotor.write(LNeutral); 
rightMotor.write(RNeutral); 
panMotor.write(0); 
delay(500); 
rightDistance = ping(); //scan to the right 
delay(500); 
panMotor.write(180); 
delay(700); 
leftDistance = ping(); //scan to the left 
delay(500); 
panMotor.write(90); //return to center 
delay(100); 
compareDistance(); 
} 
} 

void compareDistance() 
{ 
if (leftDistance>rightDistance) //if left is less obstructed 
{ 
leftMotor.write(LBackward); 
rightMotor.write(RForward); //turn left 
delay(500); 
} 
else if (rightDistance>leftDistance) //if right is less obstructed 
{ 
leftMotor.write(LForward); 
rightMotor.write(RBackward); //turn right 
delay(500); 
} 
else //if they are equally obstructed 
{ 
leftMotor.write(LForward); 
rightMotor.write(RBackward); //turn 180 degrees 
delay(1000); 
} 
} 

long ping() 
{ 
// Send out PING))) signal pulse 
pinMode(trigpin, OUTPUT); 
pinMode(echopin,INPUT); 
digitalWrite(trigpin, LOW); 
delayMicroseconds(2); 
digitalWrite(trigpin, HIGH); 
delayMicroseconds(10); 
digitalWrite(trigpin, LOW); 

//Get duration it takes to receive echo 

duration = pulseIn(echopin, HIGH); 

//Convert duration into distance 
return duration / 29 / 2; 
}
"
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top