#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);
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 flaps = 0;
int leading_edge_flap = 0;
int trimmer_tangaj = 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 flaps_decolare = 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);
pinMode(20, INPUT);
}
void loop() {
// get the sensor value
map(flaps_decolare, 0, 20, -90, 90);
int semnal_mansa_ruliu = analogRead(26);
int semnal_mansa_tangaj = analogRead(27);
int semnal_palonier = analogRead(28);
//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 (digitalRead(20) == HIGH) {
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));
} else {
}
}