hey
i was trying to make my bot just turn right using l293d and 2 dc motors at the same position(at junction of a grid)[make the right whell go backward and left wheel go forward]. This is a simple code i came up with but the problem is , my left wheel starts rotating first and my right wheel starts after a lag. plz see if there is anything wrong...
thx in advance!
int pwm2=6,rt1=11,rt2=12;//right motor
int pwm=9,lt1=1,lt2=2;//left motor
void turn_right();
void setup()
{
//all pins are made OUTPUT
}
void loop()
{
turn_right();
}
/************************************
forward means *t1=HIGH and *t2=LOW
*************************************/
void turn_right()
{
digitalWrite(rt1,LOW);//right motor bckward
digitalWrite(rt2,HIGH);
digitalWrite(lt1,HIGH);//left motor forward
digitalWrite(lt2,LOW);
//digitalWrite(pwm2,HIGH);
//digitalWrite(pwm,HIGH);
analogWrite(pwm,127);
analogWrite(pwm2,127);
delay(100);//so that the condition for stopping is not reached before it even starts turning
while(1)
{
if(condition for stopping the turning)//
return;
}
}
//just read above, turn left and go forward functions will be easy if i figure out turn_right
my question is that in the function turn_right, once i give the command
analogWrite(blahblah_pin,xyz)
does the blahblah_pin keep sending the pwm signal till the rest of the program... ie.. till while(1) condition is dissatisfied?
or do we have to keep calling the turn_right func repeatedly from loop?