#include <Servo.h>
Servo servomotor;
int ejeX = A0;
int ejeY = A1;
int pulsador_joystick = 22;
int lecturaX;
int lecturaY;
int lecturaPulsador;
int posicion_servo = 90;
void setup() {
servomotor.attach(6);
pinMode(ejeX, INPUT);
pinMode(ejeY, INPUT);
pinMode(pulsador_joystick, INPUT_PULLUP);
}
void loop() {
int lecturaX = analogRead(A0);
int lecturaY = analogRead(A1);
int lecturaPulsador = digitalRead(22);
if(lecturaX >= 550)
{
posicion_servo++;
if(posicion_servo > 180)
{
posicion_servo = 180;
}
}
if (lecturaX <= 450)
{
posicion_servo--;
if(posicion_servo < 0)
{
posicion_servo = 0;
}
}
if (lecturaPulsador == LOW)
{
posicion_servo = 90;
}
servomotor.write(posicion_servo);
delay(10);
}