Remove the setSpeed from loop(). That puts it in constant speed mode. Use the setMaxSpeed to control speed. You can change that (and acceleration) at any time.
#include <AccelStepper.h>
// changed dir and step pins to suit my setup
#define dirPin 5
#define stepPin 2
#define motorInterfaceType 1
// added enable pin for CNC shield
const byte en = 8;
// Create a new instance of the AccelStepper class:
AccelStepper stepper1 = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup()
{
// Set the maximum speed in steps per second:
pinMode(en, OUTPUT);
digitalWrite(en, LOW);
stepper1.setAcceleration(150);
}
void loop()
{
stepper1.setMaxSpeed(600);
stepper1.moveTo(100);
stepper1.run();
}
Changes to code to accommodate my CNC shield setup with Uno to test code.