Accel Stepper Question Please

Obviously I am confused about the Accel Stepper Library functions.

All of the examples i see place stepper.moveTo and stepper.run in the main loop, that's nice for a simple example, but you really can't do anything very useful.

I assumed if stepper.moveTo and stepper.run were placed in a separate function and called from the main loop, the same result would occur, but it does not. It appears the the function must be continuously called to work.

Isn't there a function that once called goes off and output the required steps without constant recalling?

amadeom: It appears the the function must be continuously called to work.

If you would look at the documentation

AccelStepper::moveTo(): Set the target position. The run() function will try to move the motor (at most one step per call) from the current position to the target position set by the most recent call to this function.

AccelStepper::run(): Poll the motor and step it if a step is due, implementing accelerations and decelerations to acheive the target position. You must call this as frequently as possible, but at least once per minimum step time interval, preferably in your main loop.

Use runToPosition() or runToNewPosition() if you want to block until the stepper reached a certain position.

amadeom: I assumed if stepper.moveTo and stepper.run were placed in a separate function and called from the main loop, the same result would occur, but it does not. It appears the the function must be continuously called to work.

stepper,run() should normally be in loop() so that it gets called in every iteration of loop(). If all the motor has arrived at its destination nothing will happen when stepper.run() is called.

You can use distanceToGo() to check if the motor has reached its destination.

Calls to moveTo() and related stuff can go wherever it is logical to put them.

And, as @LightuC has said there are also blocking calls to the library. IMHO if your program is going to be complex it is probably better to design it for non-blocking calls as it will be more complicated to remove blocking calls later if that becomes necessary.

If you are using a stepper driver that takes step and direction signals and if you don't need the acceleration features of the AccelStepper library then it is easy to control the motor without using any library.

...R Stepper Motor Basics Simple Stepper Code