Here's how I did it for 7 motors, using arrays, on a '1284P. You can shorten things for just 2 motors on an Uno or similar.
I am using 28BYJ-48 motors.
#include <Stepper.h> //include the function library, standard Arduino library
#define STEPS 64 // 64 steps per rev // hardware dependent
byte x;
unsigned long startTime;
unsigned long endTime;
unsigned long elapsedTime;
int speed[] = {
270, 270, 270, 270, 270, 270, 270,
}; // speed to move motor, 540 seems to be max for these motors
int numSteps[] = {
2048, 2500, 2500, 2500, 2500, 2500, 2500,
}; // steps to move in total = distance
int countSteps[] = {
0, 0, 0, 0, 0, 0, 0,
}; // track how much moved
byte stepsDir[] = {
0, 0, 0, 0, 0, 0, 0,
}; // counterclockwise or clockwise, 0 or 1
int stepSize[] = {
1, 1, 1, 1, 1, 1, 1,
}; // how big of a step, 2,4,8,10; 16 max to look smooth
// delayed starting times for movement effect
//int delayStart[] = {0, 1500, 2500, 3500, 4500, 5500, 6500, }; // if you don't want them to start together
int delayStart[] = {0, 0, 0, 0, 0, 0, 0,};
Stepper steppers[] = {
{STEPS, 5, 3, 4, 2},//create the stepper0 <<< Declare the pins to use, Order here is important
{STEPS, 6, 8, 7, 9}, //create the stepper1 <<< Order here is important
{STEPS, 10, 12, 11, 13}, //create the stepper2 <<< Order here is important
{STEPS, 17, 15, 16, 14}, //create the stepper3 <<< Order here is important
{STEPS, 21, 19, 20, 18}, //create the stepper4 <<< Order here is important
{STEPS, 22, 24, 23, 25}, //create the stepper5 <<< Order here is important
{STEPS, 29, 27, 28, 26}, //create the stepper5 <<< Order here is important
};
void setup()
{
Serial.begin(115200); // initialize serial communication:
for (x = 0; x < 7; x = x + 1) {
// steppers[i].whatever(); // example of using loop with this command
steppers[x].setSpeed(speed[x]);
}
}
void loop() {
for (x = 0; x < 7; x = x + 1) {
if (millis() > delayStart[x]) {
// Motor x
if (stepsDir[x] == 0) {
countSteps[x] = countSteps[x] + stepSize[x];
if (countSteps[0] == 2048){
startTime = millis();
Serial.println (startTime);
}
if (countSteps[x] >= numSteps[x]) {
countSteps[x] = numSteps[x];
stepsDir[x] = 1;
}
}
if (stepsDir[x] == 1) {
countSteps[x] = countSteps[x] - stepSize[x];
if (countSteps[x] <= 0) {
countSteps[x] = 0;
stepsDir[x] = 0;
}
}
if (stepsDir[x] == 0) {
steppers[x].step(stepSize[x]); //move one direction
}
if (stepsDir[x] == 1) {
steppers[x].step(-stepSize[x]); //move the other direction
}
}
}
}