Hi, I need some help getting this motor running for 5 seconds with the press of a button, I'm thinking its a problem with the code since I'm a beginner
This is the entirety of my code / /
#include <AccelStepper.h>
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
int button = 7;
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
pinMode(button,INPUT);
pinMode(13,OUTPUT);
stepper.setMaxSpeed(1000);
}
void loop() {
if (digitalRead(button) == HIGH) {
digitalWrite(13,HIGH);
// Set the speed in steps per second:
stepper.setSpeed(500);
// Step the motor with a constant speed as set by setSpeed():
stepper.runSpeed();
delay(5000);
}
else {
digitalWrite(13,LOW);
}
}
I'm using a Nema 17 stepper motor and a A4988 driver
any help will be appreciated