#include <AccelStepper.h>
const byte dirPin = 2;
const byte stepPin = 3;
AccelStepper stepper = AccelStepper(1, stepPin, dirPin);

void home() {
  stepper.moveTo(0);
  while (stepper.distanceToGo() != 0) stepper.run();
  Serial.println(F("at home"));
  stepper.setCurrentPosition(0);
}


void defineTarget() {
  int targetPosition = 100;
  stepper.moveTo(targetPosition);
  while (stepper.distanceToGo() != 0) stepper.run();
}

void setup() {
  Serial.begin(115200);
  stepper.setMaxSpeed(5000);
  stepper.setAcceleration(100);
}

void loop() {
  Serial.println("Going to home: ");
  home();
  delay(2000);
  Serial.println("Going to Target: ");
  defineTarget();
  delay(2000);
}
A4988