#include <Servo.h>
// Define pin numbers
int hall1 = 26;
int hall2 = 27;
int throttle = 28;
int Laileron = 7;
int Raileron = 0;
int elevator = 1;
int rudder = 2;
int flaps = 4;
int motor = 3;
// Create servo objects
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo esc;
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Attach servos to pins
servo1.attach(Laileron);
servo2.attach(Raileron);
servo3.attach(elevator);
servo4.attach(rudder);
servo5.attach(flaps);
// Initialize brushless DC motor pin
esc.attach(motor,1000,2000); +
esc.writeMicroseconds(1000);
delay(1000);
}
void loop() {
// Read analog inputs
int analogValueX = analogRead(hall1);
int analogValueY = analogRead(hall2);
int analogValueT = analogRead(throttle);
// Map analog inputs to servo positions
int Laileronservo = map(analogValueX, 630, 790, 60, 100);
int Raileronservo = map(analogValueX, 630, 790, 60, 100);
int elevatorservo = map(analogValueY, 640, 780, 60, 150);
int motorpower = map(analogValueT, 600, 1023, 0, 180);
// Set servo positions
servo1.write(Laileronservo); //Laileron
servo2.write(Raileronservo); //Raileron
servo3.write(elevatorservo); //Elevator
esc.write(motorpower);
// Print debug information
Serial.print("analogx ");
Serial.print(analogValueX);
Serial.print("analogy");
Serial.print(analogValueY);
Serial.print("analogt");
Serial.print(analogValueT);
Serial.print("laileron ");
Serial.print(Laileronservo);
Serial.print("raileron");
Serial.print(Raileronservo);
Serial.print("elevator");
Serial.print(elevatorservo);
Serial.println();
Serial.print("motor");
Serial.print(motorpower);
Serial.println();
delay(100);
}