// #include <Servo.h> libreria para arduino
#include <ESP32Servo.h>
Servo servo_x;
Servo servo_y;
Servo servo_p;
void setup() {
Serial.begin(9600);
servo_x.attach(23);
servo_y.attach(22);
servo_p.attach(21);
pinMode(32, INPUT);
pinMode(33, INPUT);
pinMode(25, INPUT_PULLUP);
servo_x.write(90); //indicar una posición inicial de x
servo_y.write(90); //indicar una posicion inicial de y
servo_p.write(0); //pulsador
}
int posición_x = 90; //angulo del eje X
int posición_y = 90; //angulo del eje y
void loop() {
int Y = analogRead(32);
int X = analogRead(33);
int P = digitalRead(25);
if(X == 0){
servo_x.write(posición_x);
posición_x = posición_x + 1;
}
if(X == 4095){
servo_x.write(posición_x);
posición_x = posición_x - 1;
}
/////////////////////////////////////
if(Y == 0){
servo_y.write(posición_y);
posición_y = posición_y + 1;
}
if(Y == 4095){
servo_y.write(posición_y);
posición_y = posición_y - 1;
}
////////////// pulsador /////////
if(P == 0){
servo_p.write(90);
delay(2000);
servo_p.write(0);
}
Serial.print("Y=");
Serial.print(Y);
Serial.print(" X=");
Serial.print(X);
Serial.print(" P=");
Serial.println(P);
}