help regarding program

hello everyone

so i have this code and i had to make some changes to it can anyone tell me if its gonna work…

it for an obstacle avoiding robot and uses one HCSRF-04 with 2 continuous rotating servos and one small servo attached to the sensor

thanks

//

#include <Servo.h> //include Servo library

const int RForward = 180;
const int RBackward = 0;
const int LForward = RBackward;
const int LBackward = RForward;
const int RNeutral = 90;
const int LNeutral = 90; //constants for motor speed
#define trigPin 12 // define the pins of your sensor
#define echoPin 13
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(9);
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()
{

long duration, distance; // start the scan
digitalWrite(trigPin, LOW);
delayMicroseconds(2); // delays are required for a succesful sensor operation.
digitalWrite(trigPin, HIGH);

delayMicroseconds(10); //this delay is required as well!
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);;

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

//

Yes, absolutely it's going to work.

No, it can't possibly work.

There - is one of those the answer you were looking for?
Seriously, how the Hell can we tell?

(23 posts and haven't got the hang of code tags yet?)

total_newbie:
really sorry what are code tags ????

Seriously?

and i meant is the code correct like are the changes correct

What changes?

Hi,
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

total_newbie:
really sorry what are code tags ????

I suspect you do not read other Threads on the Forum. You should do so - perhaps read half a dozen each day. It is a great way to learn by seeing how others tackle problems. Even if the subject is different from yours the code may have useful similarities. And you might see techniques that you could adapt for your project.

...R