pert:
You can't do that, but you can do something similar (and better):
Put the Stepper objects in an array:
Stepper steppers[] = {stepper1, stepper2, stepper3, stepper4};
Then you can do things like this:
for(x=0, x<4, x++)
{
steppers[x].move(100);
}
Note that it's a for loop you want with this syntax, not a while loop.
Thanks Pert,
I think I'm getting close to making this work. It seems like the AccelStepper functions are working with the array format, but when I go to run the motors the system goes a bit haywire. The driver board LEDs light up, and they are pulling current (more than normal), but the motors do not step. So it seems like something is not going back to the AccelStepper library correctly?
Below showing how I defined the array in the initialization section:
// NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
AccelStepper stepper1(HALFSTEP, motor1_Pin1, motor1_Pin3, motor1_Pin2, motor1_Pin4);
AccelStepper stepper2(HALFSTEP, motor2_Pin1, motor2_Pin3, motor2_Pin2, motor2_Pin4);
AccelStepper stepper3(HALFSTEP, motor3_Pin1, motor3_Pin3, motor3_Pin2, motor3_Pin4);
AccelStepper stepper4(HALFSTEP, motor4_Pin1, motor4_Pin3, motor4_Pin2, motor4_Pin4);
AccelStepper stepper5(HALFSTEP, motor5_Pin1, motor5_Pin3, motor5_Pin2, motor5_Pin4);
AccelStepper stepper6(HALFSTEP, motor6_Pin1, motor6_Pin3, motor6_Pin2, motor6_Pin4);
AccelStepper stepper7(HALFSTEP, motor7_Pin1, motor7_Pin3, motor7_Pin2, motor7_Pin4);
AccelStepper stepper8(HALFSTEP, motor8_Pin1, motor8_Pin3, motor8_Pin2, motor8_Pin4);
AccelStepper stepper9(HALFSTEP, motor9_Pin1, motor9_Pin3, motor9_Pin2, motor9_Pin4);
AccelStepper stepper10(HALFSTEP, motor10_Pin1, motor10_Pin3, motor10_Pin2, motor10_Pin4);
AccelStepper stepper11(HALFSTEP, motor11_Pin1, motor11_Pin3, motor11_Pin2, motor11_Pin4);
AccelStepper stepper12(HALFSTEP, motor12_Pin1, motor12_Pin3, motor12_Pin2, motor12_Pin4);
AccelStepper stepArray[]={stepper1,stepper2,stepper3,stepper4,stepper5,
stepper6,stepper7,stepper8,stepper9,stepper10,stepper11,stepper12};
Here is where I call the move and run functions. I'm choosing to only run the first 4 motors in this loop.
for (x = 0; x < 12; x++)
{
stepArray[x].setCurrentPosition(0);
stepArray[x].move(100);
}
while (abs(stepArray[0].distanceToGo()) > 0)
{
stepArray[0].run();
stepArray[1].run();
stepArray[2].run();
stepArray[3].run();
}
Using the below, w/o arrays, the motors work as expected.
stepper1.move(100); // 1 revolution
stepper2.move(100); // 1 revolution
stepper3.move(100); // 1 revolution
stepper4.move(100); // 1 revolution
while (abs(stepper1.distanceToGo()) > 0)
{
stepper1.run();
stepper2.run();
stepper3.run();
stepper4.run();
}