Witch code is for calling void loop? (accelstepper)

Hello.

Please help

How to make void loop repeatedly?

#include <AccelStepper.h>

AccelStepper stepper1 (1, 7, 8); 
AccelStepper stepper2 (1, 7, 8);


void setup() {
 stepper1.setMaxSpeed(1000);
 stepper1.setAcceleration(1000);

 stepper2.setMaxSpeed(1000);
 stepper2.setAcceleration(1000);


}

void loop() {
  
  stepper1.runToNewPosition(400);
  stepper2.runToNewPosition(-100);
  
 

}

?

Yea i have 1 stepper motor If is like this then working:

stepper1.runToNewPosition(400); // +400 stepper1.runToNewPosition(0); // -400

This is only example i have 4 steppers. Steppers do i job but i wish to repeat constantly.sorry for english

so in may post #2

motor run cw 400 and then ccw 100 but then stop

i wish to do same job forever. :)

 stepper1.runToNewPosition(400);
  stepper2.runToNewPosition(-100);

This tells stepper 1 to go to 400 and stop and stepper 2 to go to -100 and stop. Loop runs again and the steppers are already at those positions so nothing happens. Loop() is running, there is just nothing to do.

in reply #2 you are moving the same motor back and forth so each loop the positions change.

RunToPosition blocks. There are non blocking methods (which you will need if you want to do much with 4 steppers).
AccelStepper reference.

Examples

stepper basics

Best and fastest replay.Thank you

So is it possible to connect 1 resistance sensor and if is sensor is HIGH start loop again.

if (digitalRead (limitSensore)==HIGH) { return;

for replay #2

i don't understand well this accelstepper

So is it possible to connect 1 resistance sensor and if is sensor is HIGH start loop again.

You don't start and stop loop(). Loop() will run over and over as fast as it can. How fast that is depends on your code. If you want responsive code you can not use blocking functions (like delay() or runToNewPosition()).

if (digitalRead (limitSensore)==HIGH) {
return;

I don't know the context of that code.

i don't understand well this accelstepper

It is not easy to understand. That is why I provided all of those links. Study and run some of the examples and you should pick it up.

OK.please can you make small example.

lets say:

stepper motor go cw 500 --- stepper.runToNewPosition(500); stepper motor go ccw -300 --- stepper.runToNewPosition(-300); stepper motor go cw 200 --- stepper.runToNewPosition(200); stepper motor go cww - 100 --- stepper.runToNewPosition(-100);

and then continue from start

I have many project runung (DC motors,Stepper motors) with push buttons,potentiometers,sensors,limitswitches

But this with accelstepper is so complicate.

so i trying to build robot arm and i wish to control steppers as (lets say servo)

i know stepper cannot remember position,so i need many different movements. Firs i wish to learn with 1 stepper to understan how it works accelstepper. cw and ccw.

that is reason way i have 1 motor with:

stepper1 stepper2 stepper3 ......

to move motor cw and ccw as i wish but when is don i need code to be repeated or reloaded...