I'm having trouble with keeping it simple.
I have 8 Adafruit Motorshields, stacked on an Arduino Mega (soon to be switched with a Due)
I used the Adafruit Motorshield example using AccelStepper to create non-blocking functions running multiple motors, where you pass it the stepForwad and stepBackward function for the one specific motor.
AccelStepper accelStepper(stepForward, stepBackward);
But once you want 15 steppers, then there has to be 30 functions (2 each) which seems like it should be less repetitive passing functions with parameters like (stepForward(theMotor), stepBackward(theMotor)) which it doesn't seem to like.
I just started learning pointers this week so I may have something screwed up here but overall it does compile...
I even toyed around with making a class to manage the association between AFMS and AccelStepper but the AccelStepper doesn't like references to non-static functions... >:(
halp?!?
Adafruit_MotorShield AFMS0(0x60), AFMS1(0x61), AFMS2(0x62), AFMS3(0x63), AFMS4(0x64), AFMS5(0x65), AFMS6(0x66), AFMS7(0x67);
Adafruit_MotorShield *AFMS[] = {&AFMS0, &AFMS1, &AFMS2, &AFMS3, &AFMS4, &AFMS5, &AFMS6, &AFMS7};
const int BOARD_COUNT = 8, MOTOR_COUNT = 15, REV_STEPS = 200;
Adafruit_StepperMotor *stepper[MOTOR_COUNT];
AccelStepper accelStepper[MOTOR_COUNT];
void (*moveMotor[])(void)=
{&mf1, &mf2, &mf3, &mf4};
void initAS() {
// for loop goes here to iterate and initialize all accelSteppers
accelStepper[0] = AccelStepper(moveMotor[0], moveMotor[1]);
}
void setupMotors() {
int afmsIndex = 0;
int motorIndex = 0;
while(motorIndex < MOTOR_COUNT) {
stepper[motorIndex] = AFMS[afmsIndex]->getStepper(200, 1);
motorIndex++;
if(motorIndex < MOTOR_COUNT) {
stepper[motorIndex] = AFMS[afmsIndex]->getStepper(200, 2);
}
if (afmsIndex < BOARD_COUNT) {
afmsIndex++;
}
motorIndex++;
}
}
void mf1() {
stepper[0]->onestep(FORWARD, DOUBLE);
}
void mb1() {
stepper[0]->onestep(BACKWARD, DOUBLE);
}
void mf2() {
stepper[1]->onestep(FORWARD, DOUBLE);
}
void mb2() {
stepper[1]->onestep(BACKWARD, DOUBLE);
}
void mf3() {
stepper[0]->onestep(FORWARD, DOUBLE);
}
void mb3() {
stepper[0]->onestep(BACKWARD, DOUBLE);
}
// ... it goes on till mb14