OK I have re-writen my code and now I am having a problem where my left side motors are not being driven.I know it is not a hardware problem. I upload an older version of code with out the scanning portion and everthing works.I have included LEDS on the proto board to see if I am getting comands from my uC and right side is working but not getting anything for the left. the new code is basicly an addition to the old. I just added the servo and varibles so it can look left and right. If anyone can see why I lost leftside drive and give me an idea what I screwed up any help would be appreciated. I have posted video on my robots page so you can see what is happening.
#include <Servo.h>
Servo myservo;
#define motorlf 9
#define motorlr 10
#define motorrf 6
#define motorrr 5
int pingPin = 4;
int pos = 0;
int val2=0;
int val3=0;
int val4=0;
void setup()
{
pinMode(motorlf, OUTPUT);
pinMode(motorlr, OUTPUT);
pinMode(motorrf, OUTPUT);
pinMode(motorrr, OUTPUT);
pinMode(pingPin, OUTPUT);
myservo.attach(3);
}
void Ping()
{
long duration,cm;
pinMode (pingPin, OUTPUT);
digitalWrite(pingPin,LOW);
delayMicroseconds,(2);
digitalWrite(pingPin,HIGH);
delayMicroseconds(5);
digitalWrite(pingPin,LOW);
pinMode(pingPin,INPUT);
duration=pulseIn (pingPin,HIGH);
cm= microsecondsToCentimeters(duration);
val4=cm;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds/29/2;
}
void foward()
{
analogWrite(motorlf,250);
analogWrite(motorrf,250);
analogWrite(motorlr,0);
analogWrite(motorrr,0);
}
void reverse()
{
analogWrite(motorlr,250);
analogWrite(motorrr,250);
analogWrite(motorlf,0);
analogWrite(motorrf,0);
delay(500);
}
void halt()
{
analogWrite(motorlf,0);
analogWrite(motorrf,0);
analogWrite(motorlr,0);
analogWrite(motorrr,0);
}
void turnright()
{
analogWrite(motorlf,250);
analogWrite(motorrr,250);
analogWrite(motorlr,0);
analogWrite(motorrf,0);
delay(700);
}
void turnleft()
{
analogWrite(motorlr,250);
analogWrite(motorrf,250);
analogWrite(motorlf,0);
analogWrite(motorrr,0);
delay(700);
}
void check()
{
myservo.write(0);
delay (375);
Ping();
val2=val4;
myservo.write(180);
delay(700);
Ping();
val3=val4;
myservo.write(90);
delay(375);
}
void loop()
{
myservo.write(90);
delay(375);
Ping();
if(val4>=35){foward();}
else
{
halt();
check();
if (val2>val3){turnleft();}
else
{
if (val3>val2){turnright();}
else
{
if(val2<20&&val3<20){reverse();}}}}
}