#include <AccelStepper.h>
AccelStepper stepper(1, 9, 8); // (Typeof driver: with 2 pins, STEP, DIR)
float maxSpeed = 2500; // # of steps per second to speeed up to
unsigned long time;
unsigned long previousAccel = 0;
int interval = 100; // # of milliseconds between speed increases
void setup() {
stepper.setMaxSpeed(maxSpeed); // Set maximum speed value for the stepper
//stepper1.setAcceleration(1500); // Set acceleration value for the stepper
//stepper1.setCurrentPosition(0); // Set the current position to 0 steps
stepper.setSpeed(10);
}
void loop() {
while (stepper.speed() < maxSpeed) {
time = millis();
if (time > previousAccel + interval) {
previousAccel = time;
stepper.setSpeed(stepper.speed() + 20);
}
stepper.runSpeed();
}
stepper.setSpeed(maxSpeed);
stepper.runSpeed();
}
//stepper1.moveTo(1000); // Set desired move: 800 steps (in quater-step resolution that's one rotation)
//stepper1.runToPosition(); // Moves the motor to target position w/ acceleration/ deceleration and it blocks until is in position
//stepper1.runSpeed();
// Move back to position 0, using run() which is non-blocking - both motors will move at the same time
//stepper1.moveTo(0);
//if (stepper1.currentPosition() != 0) {
//stepper1.runSpeed();
// }