#include <AccelStepper.h>
// Define the connections to the stepper motor driver (A4988)
#define STEP_M1 3
#define DIR_M1 2
#define ENABLE_M1 4
#define STEP_M2 6
#define DIR_M2 5
#define ENABLE_M2 4
#define STEP_M3 8
#define DIR_M3 7
#define ENABLE_M3 4
#define STEP_M4 10
#define DIR_M4 9
#define ENABLE_M4 4
#define STEP_M5 23
#define DIR_M5 22
#define ENABLE_M5 4
#define STEP_M6 25
#define DIR_M6 24
#define ENABLE_M6 4
#define STEP_M7 27
#define DIR_M7 26
#define ENABLE_M7 4
#define STEP_M8 29
#define DIR_M8 28
#define ENABLE_M8 4
#define POTENTIOMETER_PIN A0
// Define the stepper motor objects
AccelStepper stepper1(AccelStepper::DRIVER, STEP_M1, DIR_M1);
AccelStepper stepper2(AccelStepper::DRIVER, STEP_M2, DIR_M2);
AccelStepper stepper3(AccelStepper::DRIVER, STEP_M3, DIR_M3);
AccelStepper stepper4(AccelStepper::DRIVER, STEP_M4, DIR_M4);
AccelStepper stepper5(AccelStepper::DRIVER, STEP_M5, DIR_M5);
AccelStepper stepper6(AccelStepper::DRIVER, STEP_M6, DIR_M6);
AccelStepper stepper7(AccelStepper::DRIVER, STEP_M7, DIR_M7);
AccelStepper stepper8(AccelStepper::DRIVER, STEP_M8, DIR_M8);
void setup()
{
// Set the maximum speed and acceleration for each stepper motor
stepper1.setMaxSpeed(1000);
stepper1.setAcceleration(500);
stepper2.setMaxSpeed(1000);
stepper2.setAcceleration(500);
stepper3.setMaxSpeed(1000);
stepper3.setAcceleration(500);
stepper4.setMaxSpeed(1000);
stepper4.setAcceleration(500);
stepper5.setMaxSpeed(1000);
stepper5.setAcceleration(500);
stepper6.setMaxSpeed(1000);
stepper6.setAcceleration(500);
stepper7.setMaxSpeed(1000);
stepper7.setAcceleration(500);
stepper8.setMaxSpeed(1000);
stepper8.setAcceleration(500);
// Set up the stepper motor pins
pinMode(ENABLE_M1, OUTPUT);
pinMode(ENABLE_M2, OUTPUT);
pinMode(ENABLE_M3, OUTPUT);
pinMode(ENABLE_M4, OUTPUT);
pinMode(ENABLE_M5, OUTPUT);
pinMode(ENABLE_M6, OUTPUT);
pinMode(ENABLE_M7, OUTPUT);
pinMode(ENABLE_M8, OUTPUT);
digitalWrite(ENABLE_M1, LOW); // Enable the stepper motor driver 1
digitalWrite(ENABLE_M2, LOW); // Enable the stepper motor driver 2
digitalWrite(ENABLE_M3, LOW); // Enable the stepper motor driver 3
digitalWrite(ENABLE_M4, LOW); // Enable the stepper motor driver 4
digitalWrite(ENABLE_M5, LOW);
digitalWrite(ENABLE_M6, LOW);
digitalWrite(ENABLE_M7, LOW);
digitalWrite(ENABLE_M8, LOW);
}
void loop()
{ // Read the potentiometer value to determine the number of steps for each motor
int potValue = analogRead(POTENTIOMETER_PIN);
int steps = map(potValue, 0, 1023, 0, 1000); // Map potentiometer value to steps (adjust as needed)
stepper1.setSpeed(500);
stepper2.setSpeed(500);
stepper3.setSpeed(500);
stepper4.setSpeed(500);
stepper5.setSpeed(500);
stepper6.setSpeed(500);
stepper7.setSpeed(500);
stepper8.setSpeed(500);
// Run each stepper motor
stepper1.run();
stepper2.run();
stepper3.run();
stepper4.run();
stepper5.run();
stepper6.run();
stepper7.run();
stepper8.run();
delay(100);
// You can add your own code here to control the motors based on sensors, buttons, etc.
}