Direction of Stepper Motor

Hey guys Im trying to write two separate codes for a Stepper. I have the following code for one direction and stops when it reaches a certain point in that direction. Whats the opposite of this code? As in what should I change to make the direction of travel opposite.

Thanks!

const int StepPin = 9;
const int DirPin = 8;

int Distance = 0; 

void setup() {                
  pinMode(DirPin, OUTPUT);     
  pinMode(StepPin, OUTPUT);
  digitalWrite(DirPin, LOW);
  digitalWrite(StepPin, LOW);
}

void loop() {
  // Take one step
  digitalWrite(StepPin, HIGH);
  delayMicroseconds(200);          
  digitalWrite(StepPin, LOW); 
  delayMicroseconds(200);
  Distance = Distance + 1; 

  // Have we reached the destination?
  if (Distance == 3600) {
    // Prevent the sketch from doing anything further
    while (true) /* Do nothing*/ ;
  }
}

Also for clarification I need to run code between movements of Stepper. So I want to move a certain distance, stop, insert code for a servo and let the servo move, and then move the motor back to the initial starting point. I know that if I use the delay command this will halt all operation after this.

Change the Dir pin to high. Changing the Dir pin changes the direction of movement.

Instead of writing your own code to control a stepper motor you can use a library that has been tested by lots of people. I use SpeedyStepper.

If you want to move the stepper first, then the servo, then the stepper you can do it using your current method. When you have reached your destination run the servo code, flip the Dir pin, then run the stepper again.

If you want to have them both run at the same time it becomes more complex. That method involves timers and interrupts, stuff a bit beyond my skill level.

These links may help

Stepper Motor Basics
Simple Stepper Code

also look up the AccelStepper library

…R