J-M-L:
Which stepper library do you use?If you use the built-in
step()function then you’ll see that the doc states so in that case the answer to your question is yes it will finish the 10 before doing the -5, it will actually finish the 10 without giving a chance for your code to run anything else if you calledmyStepper.step(10);If you have a loop() doing just single steps, then your code controls what happens by testing conditions and it’s up to you to interrupt the current flow to do something else
If you use AccelStepper then you can use API functions that never delay() or block. See how
move(),moveTo()andrun()work
I will have to look into this.
For now I am using the built-in stepper library.
I'm not home to grab the code from my laptop.
Mainly these are just to test, but one of them may end up in a practical application.
I'm using steppers to control flow mainly. A screw it attached to the stepper that moves in and out to block a flow path.
On one stepper I'm measuring temperature (cooling system)
On another I'm measuring flow.
The first one checks for temperature. I also set a target point.
If the temperature is above/below the target point, it will add/subtract 1 step via myStepper.step(1);
The problem is, the loop operates much faster than the stepper can react, so it quickly piles up the steps before the temperature hits the target, so the temperature overshoots the target, and then the process starts all over again in the opposite direction. No matter what I do the stepper motor quickly goes from minimum steps to maximum, and back again. That's why I asked if it would over-write.
I can't add a delay, because it would also delay the reading of the temperature, which must be done as quickly as possible.