#include <Servo.h>
// Servo objects
Servo myServo1;
Servo myServo2;
int servo1 = 3;
int servo2 = 5;
int joyX = A0; // More readable to use A0 and A1
int joyY = A1;
int angle1 = 90; // Start at middle position
int angle2 = 90;
const int deadZone = 50; // Adjust this for joystick sensitivity
const int stepSize = 1; // Smaller = slower movement
void setup() {
myServo1.attach(servo1);
myServo2.attach(servo2);
myServo1.write(angle1);
myServo2.write(angle2);
}
void loop() {
int valX = analogRead(joyX);
int valY = analogRead(joyY);
// Joystick center is ~512, add dead zone
if (valX < 512 - deadZone) {
angle1 = constrain(angle1 - stepSize, 10, 170);
} else if (valX > 512 + deadZone) {
angle1 = constrain(angle1 + stepSize, 10, 170);
}
if (valY < 512 - deadZone) {
angle2 = constrain(angle2 - stepSize, 10, 170);
} else if (valY > 512 + deadZone) {
angle2 = constrain(angle2 + stepSize, 10, 170);
}
myServo1.write(angle1);
myServo2.write(angle2);
delay(20); // Delay for smoother movement
}