#include <AccelStepper.h>
#define dir1 2
#define pul1 3
#define dir2 4
#define pul2 5
#define dir3 6
#define pul3 7
#define dir4 8
#define pul4 9
AccelStepper stepper1(1, pul1, dir1);
AccelStepper stepper2(1, pul2, dir2);
AccelStepper stepper3(1, pul3, dir3);
AccelStepper stepper4(1, pul4, dir4);
void setup() {
Serial.begin(9600);
stepper1.setMaxSpeed(500);
stepper2.setMaxSpeed(500);
stepper3.setMaxSpeed(500);
stepper4.setMaxSpeed(500);
stepper1.setAcceleration(250);
stepper2.setAcceleration(250);
stepper3.setAcceleration(250);
stepper4.setAcceleration(250);
}
void loop() {
int joystickValue1 = analogRead(A0);
int deviation1 = joystickValue1 - 512;
if (abs(deviation1) > 10) {
int speed1 = map(deviation1, -512, 512, -500, 500);
Serial.print(speed1);
stepper1.setSpeed(speed1);
} else {
stepper1.setSpeed(0);
}
stepper1.runSpeed();
int joystickValue2 = analogRead(A1);
int deviation2 = joystickValue2 - 512;
if (abs(deviation2) > 10) {
int speed2 = map(deviation2, -512, 512, -500, 500);
Serial.print(speed2);
stepper2.setSpeed(speed2);
} else {
stepper2.setSpeed(0);
}
stepper2.runSpeed();
int joystickValue3 = analogRead(A2);
int deviation3 = joystickValue3 - 512;
if (abs(deviation3) > 10) {
int speed3 = map(deviation3, -512, 512, -500, 500);
Serial.print(speed3);
stepper3.setSpeed(speed3);
} else {
stepper3.setSpeed(0);
}
stepper3.runSpeed();
int joystickValue4 = analogRead(A3);
int deviation4 = joystickValue4 - 512;
if (abs(deviation4) > 10) {
int speed4 = map(deviation4, -512, 512, -500, 500);
Serial.print(speed4);
stepper4.setSpeed(speed4);
} else {
stepper4.setSpeed(0);
}
stepper4.runSpeed();
}