const int dirPin = 1; // DIR pin connected to digital pin 1 const int stepPin = 0; // STEP pin connected to digital pin 0 void setup() { Serial.begin(57600); // Initialize serial communication at 9600 baud pinMode(dirPin, OUTPUT); // Set direction pin as output pinMode(stepPin, OUTPUT); // Set step pin as output } void loop() { Serial.println("Enter R for Right or L for Left:"); while (Serial.available() == 0) { // Wait for user input delay(10); // Small delay to avoid busy waiting } char input = Serial.read(); // Read the first character of the input // Handle user input if (input == 'R' || input == 'r') { Serial.println("You chose Right!"); right(); } else if (input == 'L' || input == 'l') { Serial.println("You chose Left!"); left(); } else if (input == '\n') { } else { Serial.println("Invalid input. Please enter R or L."); } delay(500); // Small delay to avoid repeated processing } void right() { // Set direction to clockwise digitalWrite(dirPin, HIGH); Serial.println("Clockwise"); for (int i = 0; i < 200; i++) { digitalWrite(stepPin, HIGH); delayMicroseconds(1000); // 1 ms delay digitalWrite(stepPin, LOW); delayMicroseconds(1000); // 1 ms delay } } void left() { // Set direction to clockwise digitalWrite(dirPin, LOW); Serial.println("Counter-Clockwise"); for (int i = 0; i < 200; i++) { digitalWrite(stepPin, HIGH); delayMicroseconds(1000); // 1 ms delay digitalWrite(stepPin, LOW); delayMicroseconds(1000); // 1 ms delay } }