Problems with a stepper motor and the AccelStepper library

Thanks for your help! :smiley:

I will carefully follow your advice.

Just, in the event that I succeed, do you have any idea about how to do the following instruction in this order :

  • Go from x to x+n;
  • Stop there until a certain condition is fulfilled (for example, another stepper goes from y to y+k);
  • "Restart" then do the x+n to x.

I'm not asking for code here, I'm just wondering if you have an idea about the feasibility of what I'm trying to do, and if possible, how would you go for it (calling a function, a loop in a loop)...

I thought about it a little and here is what I obtained :

// Let's say we need 160 steps to go from x to x+n
void loop()
{
if(Stepper1.distanceToGo()==0){ //check if motor has already finished his last move
    Stepper1.move(160*dir); //set next movement to 1600 steps (if dir is -1 it will move -1600 -> opposite direction)
    dir = dir*(-1); //negate dir to make the next movement go in opposite direction
    // Here will be my condition for my 2nd stepper to move with surely a while loop like that
    while(stepper2 hasn't finished his task)
     { 
        stepper1.stop();
        stepper2.run(k); //where k = number of step between y to y+k
     }     
  }
  
  Stepper1.run();
  Stepper2.run();
}

If you could just tell me if the way I'm taking is completely wrong, or if what I wrote has an enormous flaw, it would be super cool!

Best regards, and many thanks.