//https://www.youtube.com/watch?v=QRCvC5xhJCw
//Simultaneously moving motors to a position at a constatnt speed

#include <AccelStepper.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

#define limitSw1 4
#define limitSw2 7

bool limitSw1Status = true;
bool limitSw2Status = true;

// 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);


void setup() {
  
  stepperM1.setMaxSpeed(1000);
  stepperM2.setMaxSpeed(1000);
  stepperM3.setMaxSpeed(1000);

  pinMode(limitSw1, INPUT);
  pinMode(limitSw2, INPUT);
  
 
}//end setup()

void loop() 
{
  

while(limitSw1Status == true)
{
  stepperM1.setSpeed(500);
  stepperM1.moveTo(4000);
  stepperM1.runSpeedToPosition();

  stepperM2.setSpeed(50);
  stepperM2.moveTo(1000);
  stepperM2.runSpeedToPosition();

  if(digitalRead(limitSw1)==false)
  {
    limitSw1Status = false;
    break;
  }

}//end while(limitSw1Status == true)

while(limitSw1Status == false)
{
  stepperM3.setSpeed(100);
  stepperM3.moveTo(6000);
  stepperM3.runSpeedToPosition();

  if(digitalRead(limitSw2)==false)
  {
    limitSw1Status = true;
    break;
  }

}//end while(limitSw1Status == false)

while(1)
{
  
}

}// end loop()
   
  

A4988
A4988
A4988