Code and hardware disconnect

Hi,
I am making an Arduino obstacle robot using a radioshack ping sensor, a SEEED v2 motor shield, a DFRobot pirate 4wd base, an UNO, and that's it.
But when I add any code, the robot will either cycle through the process of turning, or not move at all. I don't have a clue and my code hit a road block. Here's my code.
const int pingpin = 7;
int lmotorcontrol = 8;
int lmotorcontrolblack = 11;
int lmotorspeed = 9;
int rmotorcontrol =12;
int rmotorcontrolblack =13;
int rmotorspeed = 10;
int Think = 2000;
int Runtime =5000;
int Slow = 230;
int Fast = 255;
long duration_p, inches_p;

void loop()
{
if(inches_p < 5)
{
turn();
}

else if (inches_p > 5)
{
forward();
}

}

void forward()//
{
analogWrite(rmotorspeed,lmotorspeed,rmotorcontrol,lmotorcontrol);
}

void turn()
{
analogWrite(lmotorcontrol, rmotorcontrol, rmotorspeed, lmotorspeed, lmotorblack, rmotorblack);
analogWrite(rmotorspeed, 500);
analogWrite(lmotorspeed, 200);
digitalWrite(lmotorcontrolblack, HIGH);
digitalWrite(rmotorcontrolblack, HIGH);
digitalWrite(rmotorcontrol, LOW);
digitalWrite(lmotorcontrol, LOW);
}

void getping_p()
{
pinMode(pingping_p, OUTPUT);
digitalWrite(pingpin_p, LOW);
delayMicroseconds(2);
digitalWrite(pingpin_p, HIGH);
delayMicroseconds(5);
digitalWrite(pingpin_p, LOW);
pinMode(pingpin_p, INPUT);
duration_p = pulseIn(pingpin_p, HIGH);
inches_p = microsecondsToInches(duration_p);
}

long microsecondsToInches(long microseconds){
return microsecond / 74/ 2;}

Hi,

analogWrite(rmotorspeed,lmotorspeed,rmotorcontrol,lmotorcontrol);

What is this line supposed to do?

Also please read this about using code tags.
http://forum.arduino.cc/index.php/topic,148850.0.html
Section 7 about code tags.

It looks like your sensor is not working, may I suggest a logical approach to this project and get each aspect working separately then combine them.

So start by just getting the sensor to work leave the motor control to later.
Use Serial.print statements, sending any sensed data, to help you, with the aid of the monitor in the IDE.

Tom....... :slight_smile:

Thank you so much for your friendly help! I have gotten both aspects running separately, but when I put it together it doesn't work. So now I am sure that it is in the code. In regards to your question, that section is supposed to be defining forward, and turning on the motors. I will add comments, and will you take a look at it again?

You don't appear to have a setup() in your code.

goacego:
In regards to your question, that section is supposed to be defining forward, and turning on the motors.

Read the reference section. AnalogWrite() must be followed by a pin number and one value

...R