#include <AccelStepper.h>
#include <MultiStepper.h>


int i=1;
// EG X-Y position bed driven by 2 steppers
// Alas its not possible to build an array of these with different pins for each :-(
AccelStepper stepper1(AccelStepper::FULL4WIRE, 2, 3, 4, 5);
AccelStepper stepper2(AccelStepper::FULL4WIRE, 6, 7, 8, 9);
AccelStepper stepper3(AccelStepper::FULL4WIRE, 10, 11, 12, 13);

// Up to 10 steppers can be handled as a group by MultiStepper
MultiStepper steppers;

void setup() {
  Serial.begin(9600);

  // Configure each stepper
  stepper1.setMaxSpeed(2000);
  stepper2.setMaxSpeed(2000);
  stepper3.setAcceleration(200);
  stepper3.setMaxSpeed(10000);

  // Then give them to MultiStepper to manage
  steppers.addStepper(stepper1);
  steppers.addStepper(stepper2);
  
}

void loop() {
  
  long positions[2]; // Array of desired stepper positions
  
  positions[0] = 2000;
  positions[1] = 300;
  steppers.moveTo(positions);
  steppers.runSpeedToPosition(); // Blocks until all are in position
  delay(1000);
  
  // Move to a different coordinate
  positions[0] = 0;
  positions[1] = 0;
  steppers.moveTo(positions);
  steppers.runSpeedToPosition(); // Blocks until all are in position
  delay(1000);



   
 
   
      stepper3.runToNewPosition(i*20);
      i=i+1;

     delay(1000);

   }