/*
  TB67S109 stepper driver module - AccelStepper example

  Install library in Arduino IDE:
  Tools / Manage Libraries / search "AccelStepper"

  AccelStepper::DRIVER is for driver boards with STEP and DIR pins.
*/

#include <AccelStepper.h>

const byte STEP_PIN = 2;
const byte DIR_PIN = 3;
const byte EN_PIN = 8;

AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);

void setup() {
  stepper.setEnablePin(EN_PIN);
  stepper.setPinsInverted(false, false, true); // EN often active-low on modules.
  stepper.enableOutputs();

  stepper.setMaxSpeed(1200);
  stepper.setAcceleration(600);
  stepper.moveTo(1600);
}

void loop() {
  if (stepper.distanceToGo() == 0) {
    stepper.moveTo(-stepper.currentPosition());
  }
  stepper.run();
}
