#include <ESP32Servo.h>
// Configura los pines para el joystick y el servomotor
const int joystickXPin = 36; // Pin VRX
const int joystickYPin = 34; // Pin VRY
const int servoPin1 = 2; // Pin para el servomotor 1
const int servoPin2 = 4; // Pin para servomotor 2
Servo myServo1;
Servo myServo2;
void setup() {
// Inicializa el servomotor
myServo1.attach(servoPin1);
myServo2.attach(servoPin2);
}
void loop() {
// Lee los valores analógicos de los ejes X e Y
int xValue = analogRead(joystickXPin);
int yValue = analogRead(joystickYPin);
// Mapea los valores a los ángulos del servomotor (0° a 180°)
int servoAngleX = map(xValue, 0, 4095, 0, 180);
int servoAngleY = map(yValue, 0, 4095, 0, 180);
// Establece los ángulos del servomotor
myServo1.write(servoAngleX);
myServo2.write(servoAngleY);
// También puedes usar myServo.write(servoAngleY) para controlar otro eje
// Espera un poco antes de leer los valores nuevamente
delay(100);
}