I'm using AccelStepper.h to run 4 stepper motors and control them individually. I have created a function but I don't know what type of data is the "AccelStepper" so I can assign it as a variable?
I attached my code, and the data type is the only thing stopping me to continue forward.
Appreciate your helps guys
void runposition_stepper (int x, AccelStepper stepper1) {
if (stepper1.currentPosition() < 0) {
while ( stepper1.currentPosition() < 0 & stepper1.currentPosition() != 0) {
stepper1.setSpeed(setspeed);
stepper1.run();
delay (2);
Serial.println (stepper1.currentPosition());
continue;
}
while (stepper1.currentPosition() != x) {
stepper1.setSpeed(setspeed);
stepper1.runSpeed();
Serial.println (stepper1.currentPosition());
continue;
}
} else if (stepper1.currentPosition() > 0) {
while ( stepper1.currentPosition() > 0 & stepper1.currentPosition() != 0) {
stepper1.setSpeed(-setspeed);
stepper1.run();
delay (2);
Serial.println (stepper1.currentPosition());
continue;
}
while (stepper1.currentPosition() != x) {
if (x < 0) {
stepper1.setSpeed(-setspeed);
stepper1.runSpeed();
Serial.println (stepper1.currentPosition());
} else if ( x > 0) {
stepper1.setSpeed(setspeed);
stepper1.runSpeed();
Serial.println (stepper1.currentPosition());
}
}
} else if (stepper1.currentPosition() == 0) {
while (stepper1.currentPosition() != x) {
if (x < 0) {
stepper1.setSpeed(-setspeed);
stepper1.runSpeed();
Serial.println (stepper1.currentPosition());
} else if ( x > 0) {
stepper1.setSpeed(setspeed);
stepper1.runSpeed();
Serial.println (stepper1.currentPosition());
}
}
}
}