// Example code of controlling a stepper motor
// First include the stepper motor library,
// this must be installed in the computer via Arduino IDE
#include <AccelStepper.h>
// Visit this site for more information https://hackaday.io/project/183279-accelstepper-the-missing-manual/details
// Set the number of the pins of the stepper motor
int fullStep = 4;
// Create a AccelStepper object, this is called stepMotor1
// in this example. Add the following arguments, first the
// number of pins (here declared by the fullStep variable),
// following by the pins that the stepper motor is connected to
AccelStepper stepMotor1 = AccelStepper(fullStep, 8, 10, 9, 11);
// In the setup the max speed, the acceleration, and the speed
// of the stepper motor object is defined
void setup() {
stepMotor1.setMaxSpeed(1000.0);
stepMotor1.setAcceleration(200.0);
stepMotor1.setSpeed(400.0);
}
// In the loop the position of the stepper motor is given,
// using moveTo, and then the motor is started with runToPosition
void loop() {
stepMotor1.moveTo(2048);
stepMotor1.runToPosition();
// This halts the Arduino for one second
delay(1000);
stepMotor1.moveTo(0);
stepMotor1.runToPosition();
delay(1000);
}