#include <AccelStepper.h>
#include <MultiStepper.h>
// Define stepper motor connections and motor interface type.
// Motor interface type must be set to 1 when using a driver
#define dirPinM1 2
#define stepPinM1 3
#define interfaceTypeM1 1
#define dirPinM2 5
#define stepPinM2 6
#define interfaceTypeM2 1
#define dirPinM3 8
#define stepPinM3 9
#define interfaceTypeM3 1
// Create a new instance of the AccelStepper class:
AccelStepper stepperM1 = AccelStepper(interfaceTypeM1, stepPinM1, dirPinM1);
AccelStepper stepperM2 = AccelStepper(interfaceTypeM2, stepPinM2, dirPinM2);
AccelStepper stepperM3 = AccelStepper(interfaceTypeM3, stepPinM3, dirPinM3);
MultiStepper steppers;
int count = 1;
void setup() {
// Set the maximum speed in steps per second:
stepperM1.setMaxSpeed(100);
stepperM2.setMaxSpeed(100);
stepperM3.setMaxSpeed(100);
stepperM3.setAcceleration(70);
steppers.addStepper(stepperM1);
steppers.addStepper(stepperM2);
steppers.addStepper(stepperM3);
}
void loop()
{
stepperM3.moveTo(500);
//while (stepperM3.currentPosition() != 300) // Full speed up to 300
//stepperM3.run();
stepperM3.stop(); // Stop as fast as possible: sets new target
stepperM3.runToPosition();
// Now stopped after quickstop
stepperM3.moveTo(-500);
//while (stepperM3.currentPosition() != 0) // Full speed up to 0
//stepperM3.run();
stepperM3.stop(); // Stop as fast as possible: sets new target
stepperM3.runToPosition();
// Now stopped after quickstop
}// end loop()