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;}