"Bounce" in one direct. in AccelStepper.h

Hello,
I need code that make stepper moving 1000 distance constantly in the same direction but with 2 secs of break between these moves,

the code:

#include <AccelStepper.h>
#define HALFSTEP 8

#define motorPin1  3     // IN1 on the ULN2003 driver 1
#define motorPin2  4     // IN2 on the ULN2003 driver 1
#define motorPin3  5     // IN3 on the ULN2003 driver 1
#define motorPin4  6     // IN4 on the ULN2003 driver 1

AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

void setup() {
  stepper1.setMaxSpeed(500.0);
  stepper1.setAcceleration(75.0);
  stepper1.setSpeed(100);
  stepper1.moveTo(1000);
}

void loop()
{    
stepper1.run();
delay(2000);
}

doesn’t work because motor makes 2-sec. break after every single step(I can see it by LEDs on motor driver), not after moving all distance,

could you explain what is wrong and how to fix it?

You must never use delay() with AccelStepper library while a motor is moving.

Perhaps you should be using runToPosition()?

Can runToPosition() be used in loop? I still see errors when I try.

Also I tried to modify this code:

// Bounce.pde

#include <AccelStepper.h>

AccelStepper stepper;
void setup()
{  
  stepper.setMaxSpeed(100);
  stepper.setAcceleration(20);
  stepper.moveTo(500);
}
void loop()
{
   if (stepper.distanceToGo() == 0)
    delay(2000);
     stepper.moveTo(-stepper.currentPosition());
      delay(2000);
   stepper.run();
}

by removing - from

stepper.moveTo(-stepper.currentPosition());

but then of course nothing happened after these 2 secs, have you any more ideas?

It's always going to go the same direction? Like for thousands of revolutions after many days?

Then each time you stop, reset the "current" position to zero. Then set the target to the value you want and call runToPosition().

Ok, I’ve got it, maybe it’s done in stupid way but works like I wanted it to(moving 1000 clockwise, wait 2 secs, again 1000 clockwise and again 2 secs - in loop with acceleration and deacceleration).

#include <AccelStepper.h>
#define HALFSTEP 8

#define motorPin1  3     // IN1 on the ULN2003 driver 1
#define motorPin2  4     // IN2 on the ULN2003 driver 1
#define motorPin3  5     // IN3 on the ULN2003 driver 1
#define motorPin4  6     // IN4 on the ULN2003 driver 1

AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

void setup() {
  stepper1.setMaxSpeed(500.0);
  stepper1.setAcceleration(75.0);
  stepper1.setSpeed(100);
  stepper1.moveTo(1000);

}

void loop() {

  if (stepper1.distanceToGo() == 0) {
    delay(2000);
    stepper1.move(1000);
    delay(2000);
  }
  stepper1.run();
}

MorganS Yes, all time the same direction, I tried runToPosition(), but there still were errors.

If you don't tell us what the errors were, we can't help you solve the problems.

The error in code with runToPosition() was

"error: no matching function for call to 'AccelStepper::runToPosition(int)'",

but code with

...
if (stepper1.distanceToGo() == 0) {
    delay(2000);
    stepper1.move(1000);
    delay(2000);
...

I've posted above works fine and does what I wanted.