Untitled
unknown
plain_text
a year ago
1.7 kB
5
Indexable
#include <Servo.h>
// Define servo objects
Servo aileronServo;
Servo elevatorServo;
Servo rudderServo;
Servo esc;
const int aileronPin = 9;
const int elevatorPin = 10;
const int rudderPin = 11;
const int escPin = 6;
const int aileronInput = 2; // PWM signal from receiver for aileron
const int elevatorInput = 3; // PWM signal from receiver for elevator
const int rudderInput = 4; // PWM signal from receiver for rudder
const int throttleInput = 5; // PWM signal from receiver for throttle
void setup() {
// Attach the servos to their respective pins
aileronServo.attach(aileronPin);
elevatorServo.attach(elevatorPin);
rudderServo.attach(rudderPin);
esc.attach(escPin);
// Initialize the inputs
pinMode(aileronInput, INPUT);
pinMode(elevatorInput, INPUT);
pinMode(rudderInput, INPUT);
pinMode(throttleInput, INPUT);
}
void loop() {
// Read PWM signals from the receiver
int aileronSignal = pulseIn(aileronInput, HIGH);
int elevatorSignal = pulseIn(elevatorInput, HIGH);
int rudderSignal = pulseIn(rudderInput, HIGH);
int throttleSignal = pulseIn(throttleInput, HIGH);
// Map the signals to the appropriate range for the servos
int aileronOutput = map(aileronSignal, 1000, 2000, 0, 180);
int elevatorOutput = map(elevatorSignal, 1000, 2000, 0, 180);
int rudderOutput = map(rudderSignal, 1000, 2000, 0, 180);
int throttleOutput = map(throttleSignal, 1000, 2000, 0, 180);
// Write the outputs to the servos
aileronServo.write(aileronOutput);
elevatorServo.write(elevatorOutput);
rudderServo.write(rudderOutput);
esc.write(throttleOutput);
// Small delay for stability
delay(20);
}
Editor is loading...
Leave a Comment