// Distancia para detectar al oponente (en cm)
#define DISTANCIA_DETECCION 20
// Tiempo de giro para búsqueda activa (en ms)
#define TIEMPO_GIRO 500
void setup() {
// Configura los pines del puente H como salidas
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
// Inicia el robot detenido
detener();
}
void loop() {
// Mide la distancia al oponente
unsigned int distancia = sonar.ping_cm();
// Si detecta al oponente dentro del rango, avanza
if (distancia > 0 && distancia = DISTANCIA_DETECCION) {
girarIzquierda();
delay(TIEMPO_GIRO);
detener();
}
}
It looks like you've shared an Arduino sketch for a robot using an ultrasonic sensor and an L298N H-bridge motor driver. How can I help you with this project? For example, would you like to create a corresponding schematic in Flux by adding the related components (e.g., an ultrasonic sensor like HC-SR04 and the L298N) or would you prefer assistance with another aspect of your design?