// Define los pines para el control del motor
#define motor1PWM 5 // Pin PWM para el motor 1
#define motor1Dir1 18 // Pin de dirección 1 para el motor 1
#define motor1Dir2 19 // Pin de dirección 2 para el motor 1
#define motor2PWM 23 // Pin PWM para el motor 2
#define motor2Dir1 22 // Pin de dirección 1 para el motor 2
#define motor2Dir2 21 // Pin de dirección 2 para el motor 2
void setup() {
// Configura los pines como salidas
pinMode(motor1PWM, OUTPUT);
pinMode(motor1Dir1, OUTPUT);
pinMode(motor1Dir2, OUTPUT);
pinMode(motor2PWM, OUTPUT);
pinMode(motor2Dir1, OUTPUT);
pinMode(motor2Dir2, OUTPUT);
}
void loop() {
//Avanza para adelante por 5 seg
digitalWrite(motor1Dir1, HIGH);
digitalWrite(motor1Dir2, LOW);
digitalWrite(motor2Dir1, HIGH);
digitalWrite(motor2Dir2, LOW);
analogWrite(motor1PWM, 255); // Velocidad máxima hacia adelante
analogWrite(motor2PWM, 200);
delay(5000); // Espera 2 segundos
//Espera por 2 seg
digitalWrite(motor1Dir1, LOW);
digitalWrite(motor1Dir2, LOW);
digitalWrite(motor2Dir1, LOW);
digitalWrite(motor2Dir2, LOW);
delay(2000);
//Gira izq
digitalWrite(motor2Dir1, HIGH);
digitalWrite(motor2Dir2, LOW);
digitalWrite(motor1Dir1, LOW);
digitalWrite(motor1Dir2, HIGH);
analogWrite(motor1PWM, 255);
analogWrite(motor2PWM, 200);
delay(2000);
//Espera por 2 seg
digitalWrite(motor1Dir1, LOW);
digitalWrite(motor1Dir2, LOW);
digitalWrite(motor2Dir1, LOW);
digitalWrite(motor2Dir2, LOW);
delay(2000);
//Gira der
digitalWrite(motor2Dir1, LOW);
digitalWrite(motor2Dir2, HIGH);
digitalWrite(motor1Dir1, HIGH);
digitalWrite(motor1Dir2, LOW);
analogWrite(motor1PWM, 255);
analogWrite(motor2PWM, 200);
delay(2000);
}