#include <ESP32Servo.h> // Librería para controlar los servos
// Definición de pines de los potenciómetros y servos
const int potPin1 = 25; // Potenciómetro 1
const int potPin2 = 35; // Potenciómetro 2
const int potPin3 = 32; // Potenciómetro 3
const int potPin4 = 33; // Potenciómetro 4
const int servoPin1 = 18; // Servo 1
const int servoPin2 = 19; // Servo 2
const int servoPin3 = 21; // Servo 3
const int servoPin4 = 22; // Servo 4
// Objetos Servo
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
void setup() {
// Configuración de los pines
pinMode(potPin1, INPUT);
pinMode(potPin2, INPUT);
pinMode(potPin3, INPUT);
pinMode(potPin4, INPUT);
// Asignar pines a los servos
servo1.attach(servoPin1);
servo2.attach(servoPin2);
servo3.attach(servoPin3);
servo4.attach(servoPin4);
}
void loop() {
// Leer valores de los potenciómetros
int potValue1 = analogRead(potPin1);
int potValue2 = analogRead(potPin2);
int potValue3 = analogRead(potPin3);
int potValue4 = analogRead(potPin4);
// Mapear los valores a un rango de 0 a 180 grados
int angle1 = map(potValue1, 0, 4095, 0, 180);
int angle2 = map(potValue2, 0, 4095, 0, 180);
int angle3 = map(potValue3, 0, 4095, 0, 180);
int angle4 = map(potValue4, 0, 4095, 0, 180);
// Mover los servos a los ángulos correspondientes
servo1.write(angle1);
servo2.write(angle2);
servo3.write(angle3);
servo4.write(angle4);
// Pequeña pausa para estabilidad
delay(15);
}