// Define pin connections
const int STEP_PIN = 3;
const int DIR_PIN = 4;

// Variables to store the direction
int direction = 0;
bool rotate = false;

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 direction:"); // Prompt user for input
}

void loop() {
  if (Serial.available() > 0) {  // Check if there is serial input available
    int newDirection = Serial.parseInt();   // Read the number of steps from serial input

    // Update the direction if a valid input is received
    if (newDirection == 1 || newDirection == 0) {
      direction = newDirection;
      rotate = true;

      // Print the entered direction to the serial monitor
      Serial.print("Direction: ");
      Serial.println(direction == 1 ? "Clockwise" : "Counter-Clockwise");

      // Set the direction based on input
      if (direction == 1) {
        digitalWrite(DIR_PIN, HIGH);  // Clockwise
      } else if (direction == 2) {
        digitalWrite(DIR_PIN, LOW);   // Counter-Clockwise
      }
    }
  }

  // Check if the motor should rotate
  if (rotate) {
    // Generate the steps continuously
    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
  }
}
mega:SCL
mega:SDA
mega:AREF
mega:GND.1
mega:13
mega:12
mega:11
mega:10
mega:9
mega:8
mega:7
mega:6
mega:5
mega:4
mega:3
mega:2
mega:1
mega:0
mega:14
mega:15
mega:16
mega:17
mega:18
mega:19
mega:20
mega:21
mega:5V.1
mega:5V.2
mega:22
mega:23
mega:24
mega:25
mega:26
mega:27
mega:28
mega:29
mega:30
mega:31
mega:32
mega:33
mega:34
mega:35
mega:36
mega:37
mega:38
mega:39
mega:40
mega:41
mega:42
mega:43
mega:44
mega:45
mega:46
mega:47
mega:48
mega:49
mega:50
mega:51
mega:52
mega:53
mega:GND.4
mega:GND.5
mega:IOREF
mega:RESET
mega:3.3V
mega:5V
mega:GND.2
mega:GND.3
mega:VIN
mega:A0
mega:A1
mega:A2
mega:A3
mega:A4
mega:A5
mega:A6
mega:A7
mega:A8
mega:A9
mega:A10
mega:A11
mega:A12
mega:A13
mega:A14
mega:A15
stepper1:A-
stepper1:A+
stepper1:B+
stepper1:B-
A4988
drv1:ENABLE
drv1:MS1
drv1:MS2
drv1:MS3
drv1:RESET
drv1:SLEEP
drv1:STEP
drv1:DIR
drv1:GND.1
drv1:VDD
drv1:1B
drv1:1A
drv1:2A
drv1:2B
drv1:GND.2
drv1:VMOT