#include <Servo.h>
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
int joyX = A0; // Joystick X-axis pin
int joyY = A1; // Joystick Y-axis pin
int joyThreshold = 10; // Joystick deadzone threshold
void setup() {
servo1.attach(9); // Servo 1 control pin
servo2.attach(10); // Servo 2 control pin
servo3.attach(3); // Servo 3 control pin
}
void loop() {
int xVal = analogRead(joyX);
int yVal = analogRead(joyY);
// Check if joystick is within deadzone, important for all codings
if (abs(xVal - 512) < joyThreshold) {
xVal = 512; // Set joystick position to center
}
if (abs(yVal - 512) < joyThreshold) {
yVal = 512; // Set joystick position to center
}
// Map joystick position to servo angles
int servo1Angle = map(xVal, 0, 1023, 0, 180);
int servo2Angle = map(yVal, 0, 1023, 0, 180);
int servo3Angle = map(yVal, 0, 1023, 0, 180);
// Move servos with a delay between them
servo1.write(servo1Angle);
delay(0);
servo2.write(servo2Angle);
delay(1);
servo3.write(servo3Angle);
delay(0);
}