#include <Servo.h>
Servo servoX;
Servo servoY;
int joystickX = A0;
int joystickY = A1;
int led1Pin = 11;
int led2Pin = 12;
void setup() {
servoX.attach(9); // Conecta el servomotor X al pin 9 (PWM)
servoY.attach(10); // Conecta el servomotor Y al pin 10 (PWM)
pinMode(led1Pin, OUTPUT); // Configura el pin del LED 1 como salida
pinMode(led2Pin, OUTPUT); // Configura el pin del LED 2 como salida
}
void loop() {
int xPosition = map(analogRead(joystickX), 0, 1023, 0, 180); // Mapea el rango del joystick a 0-180 grados
int yPosition = map(analogRead(joystickY), 0, 1023, 0, 180); // Mapea el rango del joystick a 0-180 grados
servoX.write(xPosition); // Mueve el servomotor X a la posición X
servoY.write(yPosition); // Mueve el servomotor Y a la posición Y
// Enciende el LED 1 cuando el servomotor Y está en 0 o 180 grados
if (yPosition == 0 || yPosition == 180) {
digitalWrite(led1Pin, HIGH);
} else {
digitalWrite(led1Pin, LOW);
}
// Enciende el LED 2 cuando el servomotor X está en 0 o 180 grados
if (xPosition == 0 || xPosition == 180) {
digitalWrite(led2Pin, HIGH);
} else {
digitalWrite(led2Pin, LOW);
}
delay(10); // Pequeña pausa para estabilizar los servomotores
}