#include <ESP32Servo.h>
Servo motor1;
Servo motor2;
Servo motor3;
Servo motor4;
int ejex1=14;
int ejex2=35;
int ejey1=27;
int ejey2=32;
// Valores mínimos y máximos de los servos
const int minPos = 0;
const int maxPos = 180;
void setup() {
motor1.attach(4);
motor2.attach(16);
motor3.attach(19);
motor4.attach(21);
pinMode(ejex1, INPUT);
pinMode(ejex2, INPUT);
pinMode(ejey1, INPUT);
pinMode(ejey2, INPUT);
}
void loop() {
// Leemos los valores de los joysticks
int xValue1 = analogRead(ejex1);
int yValue1 = analogRead(ejey1);
int xValue2 = analogRead(ejex2);
int yValue2 = analogRead(ejey2);
// Mapeamos los valores de los joysticks al rango de los servos
int angle1 = map(xValue1, 0, 1023, minPos, maxPos);
int angle2 = map(yValue1, 0, 1023, minPos, maxPos);
int angle3 = map(xValue2, 0, 1023, minPos, maxPos);
int angle4 = map(yValue2, 0, 1023, minPos, maxPos);
// Movemos los servos
motor1.write(angle1);
motor2.write(angle2);
motor3.write(angle3);
motor4.write(angle4);
// Delay para suavizar el movimiento (ajusta según sea necesario)
delay(15);
}