moving 2 stepper motors in the same time

hi every one
i'm looking for moving 2 stepper motors in the same time with control of speed

#include <Stepper.h>

const int stepsPerRevolution = 200;
// change this to the number of steps on your motor
//#define STEPS 200

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper myStepper1(stepsPerRevolution, 8, 9, 10, 11);
Stepper myStepper2(stepsPerRevolution, 4, 5, 6, 7);


void setup() {
 

 //initialize the serial port:
 Serial.begin(9600);
}

void loop() {
 // step one revolution in one direction:
 Serial.println("clockwise");
 myStepper1.step(stepsPerRevolution);
 myStepper1.setSpeed(100); //speed of stepper1
 myStepper2.step(stepsPerRevolution);
 myStepper2.setSpeed(30); //speed of stepper2
 delay(500);
 
 // step one revolution in the other direction:
  Serial.println("counterclockwise");
 myStepper1.step(-stepsPerRevolution);
 myStepper1.setSpeed(100); //speed of stepper1
 myStepper2.step(-stepsPerRevolution);
 myStepper2.setSpeed(30); //speed of stepper2
 delay(500);

}

my problem is that 2 stepper doesn't work in the same time . the stepper1 work and after he finished the stepper2 work

seifouar:
my problem is that 2 stepper doesn't work in the same time . the stepper1 work and after he finished the stepper2 work

That's what you told them to do. You will need to step them one step at a time to get them moving together. You will probably have to step them at different intervals to control the speed too.

Edit: Another library might make things easier. The plain old stepper library is a bit basic.

Here's how I did it for 7 motors, using arrays, on a '1284P. You can shorten things for just 2 motors on an Uno or similar.
I am using 28BYJ-48 motors.

#include <Stepper.h> //include the function library, standard Arduino library
#define STEPS 64 // 64 steps per rev // hardware dependent
byte x;
unsigned long startTime;
unsigned long endTime;
unsigned long elapsedTime;

int speed[] = {
  270, 270, 270, 270, 270, 270, 270, 
}; // speed to move motor, 540 seems to be max for these motors

int numSteps[] = {
  2048, 2500, 2500, 2500, 2500, 2500, 2500, 
}; // steps to move in total = distance

int countSteps[] = {
  0, 0, 0, 0, 0, 0, 0,
}; // track how much moved

byte stepsDir[] =  {
  0, 0, 0, 0, 0, 0, 0,
}; // counterclockwise or clockwise, 0 or 1

int stepSize[] = {
  1, 1, 1, 1, 1, 1, 1,
}; // how big of a step, 2,4,8,10; 16 max to look smooth

// delayed starting times for movement effect

//int delayStart[] = {0, 1500, 2500, 3500, 4500, 5500, 6500,  }; // if you don't want them to start together
int delayStart[] = {0, 0, 0, 0, 0, 0, 0,};

Stepper steppers[] = {
  {STEPS, 5, 3, 4, 2},//create the stepper0  <<< Declare the pins to use, Order here is important
  {STEPS, 6, 8, 7, 9}, //create the stepper1  <<< Order here is important
  {STEPS, 10, 12, 11, 13}, //create the stepper2  <<< Order here is important
  {STEPS, 17, 15, 16, 14}, //create the stepper3  <<< Order here is important
  {STEPS, 21, 19, 20, 18}, //create the stepper4  <<< Order here is important
  {STEPS, 22, 24, 23, 25}, //create the stepper5  <<< Order here is important
  {STEPS, 29, 27, 28, 26}, //create the stepper5  <<< Order here is important
};

void setup()
{
  Serial.begin(115200); // initialize serial communication:
  for (x = 0; x < 7; x = x + 1) {
    //  steppers[i].whatever();  // example of using loop with this command
    steppers[x].setSpeed(speed[x]);
  }
}
void loop() {
  for (x = 0; x < 7; x = x + 1) {
    if (millis() > delayStart[x]) {
      // Motor x
      if (stepsDir[x] == 0) {
        countSteps[x] = countSteps[x] + stepSize[x];
        if (countSteps[0] == 2048){
          startTime = millis();
          Serial.println (startTime);
        }
        if (countSteps[x] >= numSteps[x]) {
          countSteps[x] = numSteps[x];
          stepsDir[x] = 1;
        }
      }

      if (stepsDir[x] == 1) {
        countSteps[x] = countSteps[x] - stepSize[x];
        if (countSteps[x] <= 0) {
          countSteps[x] = 0;
          stepsDir[x] = 0;
        }
      }

      if (stepsDir[x] == 0) {
        steppers[x].step(stepSize[x]); //move one direction
      }
      if (stepsDir[x] == 1) {
        steppers[x].step(-stepSize[x]); //move the other direction
      }
    }
  }
}

seifouar:
my problem is that 2 stepper doesn't work in the same time . the stepper1 work and after he finished the stepper2 work

You also need to specify whether {A} it is sufficient for both motors to start at the same time but for motorA to stop before motorB or {B} whether both motors must start and stop at the same time even though they move different numbers of steps. This latter {B} type of motion is standard for 3D printers, for example.

If option {A} is acceptable then the AccelStepper library can handle that as standard with its run() and runSpeed() functions.

If you need option {B} you could use the MultiStepper version of the AccelStepper library but it cannot handle acceleration. Or, of course, you can write your own code.

...R