#include <Arduino.h>
#include "A4988.h"//A4988 stepper motor driver library.
// change this to the number of steps on your motor
#define MOTOR_STEPS 90
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// FLAPERON R
#define DIR 0
#define STEP 1
#define MS1 2
#define MS2 20
#define MS3 21
A4988 stepper(MOTOR_STEPS, DIR, STEP, MS1, MS2, MS3);
//FLAPERON L
#define DIR 3
#define STEP 4
#define MS1 5
#define MS2 20
#define MS3 21
A4988 stepper1(MOTOR_STEPS, DIR, STEP, MS1, MS2, MS3);
//STABILATOR R
#define DIR 6
#define STEP 7
#define MS1 8
#define MS2 20
#define MS3 21
A4988 stepper2(MOTOR_STEPS, DIR, STEP, MS1, MS2, MS3);
//STABILATOR L
#define DIR 9
#define STEP 10
#define MS1 11
#define MS2 20
#define MS3 21
A4988 stepper3(MOTOR_STEPS, DIR, STEP, MS1, MS2, MS3);
//DIRECTIE
#define DIR 12
#define STEP 13
#define MS1 14
#define MS2 20
#define MS3 21
A4988 stepper4(MOTOR_STEPS, DIR, STEP, MS1, MS2, MS3);
//LEADING EDGE FLAP
#define DIR 15
#define STEP 16
#define MS1 17
#define MS2 20
#define MS3 21
A4988 stepper5(MOTOR_STEPS, DIR, STEP, MS1, MS2, MS3);
int semnal_mansa_ruliu = 0;
int semnal_mansa_tangaj = 0;
int semnal_palonier = 0;
int actuator_flaperon_R = 0;
int actuator_flaperon_L = 0;
int actuator_stabilator_R = 0;
int actuator_stabilator_L = 0;
int actuator_directie = 0;
int viteza = 0;
int altitudine = 0;
int trimmer_tangaj_fata = 0;
int trimmer_ruliu_dreapta = 0;
int trimmer_tangaj_spate = 0;
int trimmer_ruliu_stanga = 0;
int stabilator_R_viraj_dreapta = 0;
int stabilator_L_viraj_dreapta = 0;
int stabilator_R_stabilizare = 0;
int stabilator_L_stabilizare = 0;
int flaps_0 = 0;
int flaps_2 = 0;
int flaps_actionat = 0;
int leading_edge_2 = 0;
int previous = 0;// the previous reading from the analog input
int previous1 = 0;
int previous2 = 0;// the previous reading from the analog input
int previous3 = 0;
int previous4 = 0;
int previous5 = 0;
int previous6 = 0;
int previous7 = 0;
int previous8 = 0;
int previous9 = 0;
int previous10 = 0;
int previous11 = 0;
int previous12 = 0;
int previous13 = 0;
int previous14 = 0;
int previous15 = 0;
void setup() {
//FLAPERON R
stepper.setRPM(150);//Setting the motor speed
stepper.setMicrostep(4);
//FLAPERON L
stepper1.setRPM(150);//Setting the motor speed
stepper1.setMicrostep(4);
//STABILATOR R
stepper2.setRPM(150);//Setting the motor speed
stepper2.setMicrostep(4);
//STABILATOR L
stepper3.setRPM(150);//Setting the motor speed
stepper3.setMicrostep(4);
//DIRECTIE
stepper4.setRPM(150);//Setting the motor speed
stepper4.setMicrostep(4);
//LEADING EDGE FLAP
stepper5.setRPM(150);//Setting the motor speed
stepper5.setMicrostep(4);
pinMode(20, INPUT);
pinMode(21, INPUT);
flaps_0 = 0;
flaps_2 = -2;
flaps_actionat = 20;
leading_edge_2 = -2;
stabilator_R_viraj_dreapta = -90;
stabilator_L_viraj_dreapta = 90;
}
void loop() {
// get the sensor value
int semnal_mansa_ruliu = analogRead(26);
int semnal_mansa_tangaj = analogRead(27);
int semnal_palonier = analogRead(28);
int trimmer_tangaj = analogRead(28);
viteza = digitalRead(21);
altitudine = digitalRead(20);
//FLAPERON DREAPTA
actuator_flaperon_R=map(semnal_mansa_ruliu,0,1023,-90,90);//0 to 1023 is the sensor range, 0 to 400 is the stepper's stepping range.
stepper.move((actuator_flaperon_R - previous));
// remember the previous value of the sensor
previous = actuator_flaperon_R;
//FLAPERON STANGA
actuator_flaperon_L=map(semnal_mansa_ruliu,0,1023,90,-90);//0 to 1023 is the sensor range, 0 to 400 is the stepper's stepping range.
stepper1.move((actuator_flaperon_L - previous1));
// remember the previous value of the sensor
previous1 = actuator_flaperon_L;
//STABILATOR DREAPTA
actuator_stabilator_R=map(semnal_mansa_tangaj,0,1023,-90,90);//0 to 1023 is the sensor range, 0 to 400 is the stepper's stepping range.
stepper2.move((actuator_stabilator_R - previous2));
// remember the previous value of the sensor
previous2 = actuator_stabilator_R;
//STABILATOR STANGA
actuator_stabilator_L=map(semnal_mansa_tangaj,0,1023,-90,90);//0 to 1023 is the sensor range, 0 to 400 is the stepper's stepping range.
stepper3.move((actuator_stabilator_L - previous3));
// remember the previous value of the sensor
previous3 = actuator_stabilator_L;
//DIRECTIE
actuator_directie=map(semnal_palonier,0,1023,90,-90);//0 to 1023 is the sensor range, 0 to 400 is the stepper's stepping range.
stepper4.move((actuator_directie - previous4));
// remember the previous value of the sensor
previous4 = actuator_directie;
//Flaps taxi
if (viteza == HIGH ) {
stepper5.move((leading_edge_2 - previous5));
previous5 = leading_edge_2;
} else {
stepper5.move((leading_edge_2 - previous5));
previous5 = leading_edge_2;
}
// Stabilator viraj dreapta
if (semnal_mansa_ruliu > 980 && semnal_mansa_tangaj > 980) {
stepper2.move((stabilator_R_viraj_dreapta - previous10));
previous10 = stabilator_R_viraj_dreapta;
stepper3.move((stabilator_L_viraj_dreapta - previous11));
previous11 = stabilator_L_viraj_dreapta;
}
//PILOT AUTOMAT
delay(100);
}