int LA=14;
int LB=15;
int RA=16;
int RB=17;
int EN1=3;
int EN2=5;
const int LS=2;
const int RS=6;
void setup()
{
pinMode(LA,OUTPUT);
pinMode(LB,OUTPUT);
pinMode(RA,OUTPUT);
pinMode(RB,OUTPUT);
pinMode(EN1,OUTPUT);
pinMode(EN2,OUTPUT);
pinMode(LS,INPUT);
pinMode(RS,INPUT);
}
void loop()
{
int LI=digitalRead(LS);
int RI=digitalRead(RS);
if (LI==LOW && RI==LOW) {forward(0.1);pause(0.2);}
else if (LI==HIGH && RI==LOW) {right(0.25);pause(0.2);}
else if (LI==LOW && RI==HIGH){left(0.25);pause(0.2);};
}
void forward(float a)
{
analogWrite(EN1,150);
digitalWrite(LA,HIGH);
digitalWrite(LB,LOW);
analogWrite(EN2,164);
digitalWrite(RA,HIGH);
digitalWrite(RB,LOW);
delay(a*1000);
}
void left(float c)
{
analogWrite(EN1,0);
digitalWrite(LA,LOW);
digitalWrite(LB,LOW);
analogWrite(EN2,200);
digitalWrite(RA,HIGH);
digitalWrite(RB,LOW);
delay(c*1000);
}
void right(float d)
{
analogWrite(EN1,200);
digitalWrite(LA,HIGH);
digitalWrite(LB,LOW);
analogWrite(EN2,0);
digitalWrite(RA,LOW);
digitalWrite(RB,LOW);
delay(d*1000);
}
void pause(float e)
{
analogWrite(EN1,150);
digitalWrite(LA,LOW);
digitalWrite(LB,LOW);
analogWrite(EN2,188);
digitalWrite(RA,LOW);
digitalWrite(RB,LOW);
delay(e*1000);
}