#include <AccelStepper.h>
#include <AccelStepperWithDistance.h>
#define STEP_PIN 3
#define DIR_PIN 2
AccelStepperWithDistance stepper(AccelStepperWithDistance::DRIVER, STEP_PIN, DIR_PIN);
void setup() {
stepper.setMaxSpeed(1000);
stepper.setAcceleration(500);
stepper.setStepsPerRotation(200); // For a 1.8° stepper motor
stepper.setMicroStep(16); // If using 1/16 microstepping
stepper.setDistancePerRotation(1000); // If one rotation moves 8mm
}
void loop() {
stepper.runToNewDistance(100); // Move 100mm
delay(1000);
stepper.runToNewDistance(0); // Return to starting position
delay(1000);
}