Help with AccelStepper

Help with AccelStepper

Hello,
Because I am a newbie with that library, how I can make the motor to run forever?
With the code that I have, the motor stop when it reach the pos.

#include <AccelStepper.h>

AccelStepper stepper(1, 9, 8);

int pos = 100000;

void setup(){
  stepper.setMaxSpeed(2000);
  stepper.setAcceleration(400);
}

void loop(){
  stepper.run();
  stepper.moveTo(pos);
}

And if i remove stepper.moveTo(pos); it doesn’t move.
Any help?

Thank you.

What do you think moveTo(10000) means? What do you think run() does?

What is going to happen when the stepper has done stepping 10,000 times?

A stepper is not intended to run continuously. It is intended to take a discrete number of steps. You change to number of steps when it completes the number you told it to take last time.

PaulS:
What do you think moveTo(10000) means? What do you think run() does?

What is going to happen when the stepper has done stepping 10,000 times?

A stepper is not intended to run continuously. It is intended to take a discrete number of steps. You change to number of steps when it completes the number you told it to take last time.

No you don't understand,
I want to change the code so the motor run forever.
But when I remove stepper.moveTo(pos); line it's doesn't run.

Maybe I missed some lines of code, but I don't know the library that's why I need help

No you don't understand,

Yes, I do. It's you that don't understand.

moveTo() is like saying "Go stand on the red square". run() is saying "Take on step, unless you are standing on the red square".

Now, what is going to happen when I'm standing on the red square? You can keep yelling "Run, damn it", until you keel over with a heart attack, and I'm not going to move a step BECAUSE I AM ALREADY THERE.

Once I get to the red square, I stay there, until you say "Now, go to the blue square" and call run().

PaulS:

No you don't understand,

Yes, I do. It's you that don't understand.

moveTo() is like saying "Go stand on the red square". run() is saying "Take on step, unless you are standing on the red square".

Now, what is going to happen when I'm standing on the red square? You can keep yelling "Run, damn it", until you keel over with a heart attack, and I'm not going to move a step BECAUSE I AM ALREADY THERE.

Once I get to the red square, I stay there, until you say "Now, go to the blue square" and call run().

Ok,
This library has any other commands so the motor run forever ?

This library has any other commands so the motor run forever ?

The two you have are sufficient. Well, almost.

Have you ever played with a laser pointer and a cat? What happens if you hold the laser pointer still (moveTo(10000))? The cat loses interest. What happens if you keep moving the laser pointer (moveTo(pos); pos+=1000;)? The cat keeps chasing it forever.

All you have to do is keep changing the target. It's best to not change it too fast, so you'll need to look at the library methods. There are methods to tell you how far the stepper is from where you told it to go, and to tell you if the stepper is where you told it to go.

If the number of steps to go is 0, or if you are where you told it to go, change where you tell it to go, then tell it to go to the new position.

Why ARE you trying to make a stepper emulate a standard electric motor?