running 2 stepper with accelstepper together and seperate

hello everybody

first i am sorry about my poor english., i am just start with the arduino and the stepper, and i am lost …
i want to do the following

stepper 1 and stepper 2 move at the same time to ( lets say , position 10000)

this i could do with the accelstepper example… but now i want the steppers to stay for 1 sec. , than stapper 1
should move to position 5000 after another delay stepper 2 should move as well.,

now ( for example ) i want again that they move together …

if i start with the delay … everythig stops ( move only step by step)
i did a code were the steppers are moving , but only one by one… but 2 or 3 moves they shoud do
together .,

i hope somebody can help, would be wery nice

thx in advance

</>

#include <AccelStepper.h>

#define STEPPER1_DIR_PIN 3
#define STEPPER1_STEP_PIN 2

#define STEPPER2_DIR_PIN 7
#define STEPPER2_STEP_PIN 6

#define STEPPER3_DIR_PIN 8
#define STEPPER3_STEP_PIN 9

AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);
AccelStepper stepper2(AccelStepper::DRIVER, STEPPER2_STEP_PIN, STEPPER2_DIR_PIN);
AccelStepper stepper3(AccelStepper::DRIVER, STEPPER3_STEP_PIN, STEPPER3_DIR_PIN);

void setup()
{
stepper1.setMaxSpeed(2300.0);
stepper1.setAcceleration(300.0);

stepper2.setMaxSpeed(2300.0);
stepper2.setAcceleration(300.0);

stepper3.setMaxSpeed(500.0);
stepper3.setAcceleration(80.0);
}

void loop()
{

{
stepper1.runToNewPosition(62000);
stepper2.runToNewPosition(80000);
delay(0);

stepper1.runToNewPosition(20000);
stepper2.runToNewPosition(45000);
delay(1000);
}
{
{
stepper3.runToNewPosition(4000);
}
stepper1.runToNewPosition(10000);
delay(1500);
stepper2.runToNewPosition(80000);
delay(1500);
}
stepper1.runToNewPosition(0);
stepper2.runToNewPosition(0);
while(1) { }
}

</>

Please modify your post and use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum

And please use the Auto Format tool to indent your code properly as that makes it very much easier to read

To do what you want it will be essential to get rid of all the delay()s. Use millis() to manage timing without blocking as in Several Things at a Time

And don’t use the blocking commands from AccelStepper such as runToNewPosition(). Just use run() (one for each motor) at the bottom of loop() and cause the different actions to happen by changing the destination at the appropriate times. That will probably make the code much simpler.

Make sure that loop() can repeat very quickly.

…R

If you want separate control of movement don't use any blocking functions like runToPosition(), stick to move()/moveTo() and use run() inside loop for each motor. Ensure loop runs frequently (no delays() or other blocking functions in your code.

To run sequentially:

stepper1.runToNewPosition(62000);  // Function returns when position is reached
stepper2.runToNewPosition(80000);

To run together:

stepper1.moveTo(62000);  // Function returns immediately. Call run() to move.
stepper2.moveTo(80000);
// Run both until both reach position
while (!stepper1.run() || !stepper2.run());