#include <Servo.h>
// Pins for the servo motors
const int servo1Pin = 9; // PWM pin for servo1
const int servo2Pin = 10; // PWM pin for servo2
// Pins for the joysticks
const int joystick1XPin = A0;
const int joystick1YPin = A1;
// Servo objects
Servo servo1;
Servo servo2;
// Deadzone for joysticks
const int joystickDeadzone = 20;
void setup() {
// Attach the servo motors to their respective pins
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
// Start serial communication
Serial.begin(9600);
}
void loop() {
// Read the joystick values
int joystick1XValue = analogRead(joystick1XPin);
int joystick1YValue = analogRead(joystick1YPin);
// Apply deadzone to joystick values
if (abs(joystick1XValue - 512) < joystickDeadzone) {
joystick1XValue = 512;
}
if (abs(joystick1YValue - 512) < joystickDeadzone) {
joystick1YValue = 512;
}
// Map the joystick values to servo angles
int servo1Angle = map(joystick1XValue, 0, 1023, 0, 180);
int servo2Angle = map(joystick1YValue, 0, 1023, 0, 180);
// Move the servo motors to the mapped angles
servo1.write(servo1Angle);
servo2.write(servo2Angle);
// Print joystick values to serial monitor
Serial.print("Joystick 1 X: ");
Serial.print(joystick1XValue);
Serial.print(", Y: ");
Serial.println(joystick1YValue);
delay(100);
}