#include <Servo.h>
const int servoXPin = 5; // The pin that the X-axis servo is connected to
const int servoYPin = 6; // The pin that the Y-axis servo is connected to
const int joystickXPin = A1; // The pin that the joystick's X axis is connected to
const int joystickYPin = A2; // The pin that the joystick's Y axis is connected to
Servo servoX; // Create a servo object for the X-axis servo
Servo servoY; // Create a servo object for the Y-axis servo
void setup() {
servoX.attach(servoXPin); // Attach the X-axis servo to the servo pin
servoY.attach(servoYPin); // Attach the Y-axis servo to the servo pin
pinMode(joystickXPin, INPUT); // Set the joystick X axis pin as an input
pinMode(joystickYPin, INPUT); // Set the joystick Y axis pin as an input
}
void loop() {
// Read the value of the joystick's X and Y axes
int joystickXValue = analogRead(joystickXPin);
int joystickYValue = analogRead(joystickYPin);
// Calculate the servo angles based on the joystick X and Y values
int servoXAngle = map(joystickXValue, 0, 1023, 0, 180);
int servoYAngle = map(joystickYValue, 0, 1023, 0, 180);
// Set the servo angles
servoX.write(servoXAngle);
servoY.write(servoYAngle);
// Repeat the sequence at a rate of 50 times per second
delay(20);
}