#define DIR 5
#define PUL 6
#define buttonPin 2

unsigned long speed_W = 1000;   // Speed of stepper motor in CCW direction (in microseconds) Lower = Faster
unsigned long steps_X = 1000;   // How many steps to take in CCW direction

unsigned long speed_Y = 1500;   // Speed of stepper motor in CW direction (in microseconds) Lower = Faster
unsigned long steps_Z = 800;    // How many steps to take in CW direction

int CW_DIR = HIGH;  // Direction when motor moves CW
int CCW_DIR = LOW;  // Direction when motor moves CCW

unsigned long lastBtnPress = 0;
bool startSeq = false;

void setup() {
  Serial.begin(9600);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(DIR, OUTPUT);
  pinMode(PUL, OUTPUT);

}

void loop() {

  if (digitalRead(buttonPin) == LOW) { // If button pressed
    if (millis() - lastBtnPress > 50) {
      Serial.println("Button pressed.");
      startSeq = true;  // Start the sequence
    }
    lastBtnPress = millis();
  }

  if (startSeq == true) {
    digitalWrite(DIR, CCW_DIR);  // Set the direction to CCW

    for (int i = 0; i < steps_X; i++) {
      digitalWrite(PUL, HIGH);
      delayMicroseconds(speed_W);
      digitalWrite(PUL, LOW);
      delayMicroseconds(speed_W);
    }

    delay(1000);

    digitalWrite(DIR, CW_DIR);  // Set the direction to CW

    for (int i = 0; i < steps_Z; i++) {
      digitalWrite(PUL, HIGH);
      delayMicroseconds(speed_Y);
      digitalWrite(PUL, LOW);
      delayMicroseconds(speed_Y);
    }

    startSeq = false; // Reset until next time button pressed
  }
}
A4988