// Define pin connections
const int STEP_PIN = 3;
const int DIR_PIN = 4;
// Variables to store the number of steps
int steps = 0;
void setup() {
pinMode(DIR_PIN, OUTPUT); // Set DIR_PIN as output
pinMode(STEP_PIN, OUTPUT); // Set STEP_PIN as output
Serial.begin(9600); // Initialize the serial port
Serial.println("Enter steps:"); // Prompt user for input
}
void loop() {
if (Serial.available() > 0) { // Check if there is serial input available
steps = Serial.parseInt(); // Read the number of steps from serial input
// Print the entered values to the serial monitor
Serial.print("Step: ");
Serial.print(steps);
Serial.println(" ");
// Check if the entered values are valid
if (steps > 0) {
digitalWrite(DIR_PIN, HIGH); // Set the direction
for (int i = 0; i < steps; i++) { // Loop to generate the steps
digitalWrite(STEP_PIN, HIGH); // Set STEP_PIN high
delayMicroseconds(3000); // Wait for the pulse delay time
digitalWrite(STEP_PIN, LOW); // Set STEP_PIN low
delayMicroseconds(3000); // Wait for the pulse delay time
}
}
// Reset the variables
}
}