/* Example sketch to control a stepper motor
with DRV8825 stepper motor driver, AccelStepper library
and Arduino: acceleration and deceleration.
More info: https://www.makerguides.com */
#include "AccelStepper.h"
const int BUZZER = 0;
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 1
#define stepPin 2
#define motorInterfaceType 1
// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
pinMode(BUZZER, OUTPUT);
// Set the maximum speed and acceleration:
stepper.setMaxSpeed(470);
stepper.setAcceleration(400);
}
void loop() {
// Set the target position:
stepper.moveTo(3200);
// Run to target position with set speed and acceleration/deceleration:
stepper.runToPosition();
delay(300);
// Move back to zero:
stepper.moveTo(0);
stepper.runToPosition();
delay(300);
tone(BUZZER, 440, 1000); //Set the voltage to high and makes a noise
//delay(100);//Waits for 1000 milliseconds
noTone(BUZZER);//Sets the voltage to low and makes no noise
//delay(1000);//Waits for 1000 milliseconds
}