#include <AccelStepper.h>
#define STEP_PIN 2
#define DIR_PIN 3
#define ENABLE_PIN 4
const int stepsPerRevolution = 200; // Moved to the global scope
const int rpm = 60; // Moved to the global scope
// pinMode(STEP_PIN, OUTPUT);
// pinMode(DIR_PIN, OUTPUT);
// pinMode(ENABLE_PIN, OUTPUT);
void rotateMotor(int direction) {
digitalWrite(DIR_PIN, direction); // Set direction
digitalWrite(ENABLE_PIN, LOW); // Enable the motor
int usDelay = 60000000 / (stepsPerRevolution * rpm); // Calculate microseconds delay per step for desired RPM
for (int i = 0; i < stepsPerRevolution; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(usDelay);
}
digitalWrite(ENABLE_PIN, HIGH); // Disable the motor
}
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(ENABLE_PIN, OUTPUT);
}
void loop() {
rotateMotor(HIGH);
delay(1000);
}