#include <Servo.h>
// Define servos
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
// Define joystick pins
int joyX = A0;
int joyY = A1;
void setup() {
// Attach servos to Arduino pins
servo1.attach(3);
servo2.attach(5);
servo3.attach(6);
servo4.attach(9);
// Initialize serial communication
Serial.begin(9600);
}
void loop() {
// Read joystick values
int xVal = analogRead(joyX);
int yVal = analogRead(joyY);
// Map joystick values to servo angles (0 to 180)
int servoPos1 = map(yVal, 0, 1023, 0, 180);
int servoPos2 = map(yVal, 0, 1023, 180, 0);
int servoPos3 = map(xVal, 0, 1023, 0, 180);
int servoPos4 = map(xVal, 0, 1023, 180, 0);
// Control servos based on joystick movement
servo1.write(servoPos1);
servo2.write(servoPos2);
servo3.write(servoPos3);
servo4.write(servoPos4);
// Debug output
Serial.print("X: ");
Serial.print(xVal);
Serial.print(" Y: ");
Serial.print(yVal);
Serial.print(" Servo1: ");
Serial.print(servoPos1);
Serial.print(" Servo2: ");
Serial.print(servoPos2);
Serial.print(" Servo3: ");
Serial.print(servoPos3);
Serial.print(" Servo4: ");
Serial.println(servoPos4);
delay(50); // Small delay to prevent excessive updates
}
--------------------------------------------------------wing-----------------------
--------------------------------------------------------wing-----------------------