Paso 1: Diagrama del circuito y código
CÓDIGO:
const int RightMotor = 12;
const int LeftMotor = 11;
const int RightSensor = 1;
const int LeftSensor = 2;
int SensorLeft;
int SensorRight;
int SensorDifference;
void setup() {}
pinMode (LeftMotor, salida);
pinMode (RightMotor, salida);
pinMode (LeftSensor, entrada);
pinMode (RightSensor, entrada);
digitalWrite (A1, alto);
digitalWrite (A2, alto);
Serial.Begin(9600);
Serial.println ("\nBeginning la luz buscando comportamiento");
}
void loop() {}
SensorLeft = 1023 - analogRead(LeftSensor);
Delay(1);
SensorRight = 1023 - analogRead(RightSensor);
Delay(1);
SensorDifference = abs (SensorLeft - SensorRight);
Si (SensorLeft > 500 & & SensorRight > 500) {}
Si (SensorLeft > SensorRight & & SensorDifference > 75) {}
digitalWrite (RightMotor, alto);
digitalWrite (LeftMotor, bajo);
}
Si (SensorLeft < SensorRight & & SensorDifference > 75) {}
digitalWrite (RightMotor, bajo);
digitalWrite (LeftMotor, alto);
}
Si (SensorDifference < 75) {}
digitalWrite (RightMotor, alto);
digitalWrite (LeftMotor, alto);
}
}
Si (SensorLeft < 500 & & SensorRight < 500) {}
Si (SensorLeft > SensorRight & & SensorDifference > 75) {}
digitalWrite (RightMotor, bajo);
digitalWrite (LeftMotor, bajo);
}
}
}