#include <Servo.h>
#include <Joystick.h>
Servo myServo;
Joystick myJoystick(A0, 10);
int servoPosition = 90; // Initial position of the servo
void setup() {
myServo.attach(9); // Connect the servo to pin 9
}
void loop() {
int joystickValue = myJoystick.read();
if (joystickValue < 512) {
// Joystick pushed left, move servo slowly to the left
servoPosition = max(0, servoPosition - 1);
} else if (joystickValue > 512) {
// Joystick pushed right, move servo slowly to the right
servoPosition = min(180, servoPosition + 1);
}
myServo.write(servoPosition);
delay(15); // Adjust delay as needed for smooth movement
}