void setup()
{
pinMode(3,OUTPUT); //DER AVANZA
pinMode(9,OUTPUT); //IZQ AVANZA
pinMode(5,OUTPUT); //DER RETROCEDE
pinMode(6,OUTPUT); //IZQ RETROCEDE
pinMode(A1,INPUT); //SENSOR FRONTAL ANALOGO
pinMode(A2,INPUT); //SENSOR TRASERO ANALOGO
pinMode(7,INPUT); //SENSOR FRONTAL DETECTOR
pinMode(11,INPUT); //SENSOR DERECHA DETECTOR
pinMode(10,INPUT); //SENSOR IZQUIERDA DETECTOR
}
void avanzar()
{
analogWrite(3,255);
analogWrite(9,255);
analogWrite(5,0);
analogWrite(6,0);
}
void retrocede()
{
analogWrite(5,200);
analogWrite(6,230);
analogWrite(9,0);
analogWrite(3,0);
}
void parar()
{
analogWrite(9,0);
analogWrite(6,0);
analogWrite(5,0);
analogWrite(3,0);
}
void izquierda()
{
analogWrite(5,0);
analogWrite(6,0);
analogWrite(3,255);
analogWrite(9,190);
}
void derecha()
{
analogWrite(3,150);
analogWrite(9,255);
analogWrite(5,0);
analogWrite(6,0);
}
void retrocedeizq()
{
analogWrite(5,255);
analogWrite(6,100);
analogWrite(3,0);
analogWrite(9,0);
}
void loop()
{
int SF=0;
int ST=0;
SF=analogRead(1);
ST=analogRead(2);
if ((SF)<=800 and(ST)<=800)
{
avanzar();
}
if ((SF)>=800 and (ST)<=800)
{
retrocede();
delay(800);
retrocedeizq();
delay(800);
}
if ((SF)<=800 and(ST)<=800 and digitalRead(2)==0)
{
avanzar();
izquierda();
}
}