Driving a stepper multiple defined number of steps.

Hello all, new to the forum but I have been lurking for a while and trying to learn as I go.

I have run into an issue where I would love to have some advice.

In this project I would like to drive a stepper using the Eazydriver a pre-determined number of steps and once that line of code is executed, if need be drive the stepper another but different pre-determined number of steps using an input to start the movement.

Is this even possible?

I have tried several different approaches to accomplishing this goal but seem to fall short every time.

Below is an example of the test code.

Thank You in advance!

#define DISTANCE 384
#define DISTANCE2 24

int StepCounter = 0;
int StepCounter2 = 0;
int Stepping = false;
int Singlestepping = false;


void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);

  pinMode(3, INPUT);
  pinMode(4, INPUT);

}

void loop() {
  if (digitalRead(3) == LOW && Stepping == false)
  {
    Stepping = true;
  }

  else if  (digitalRead(4) == LOW && Singlestepping == false)
  {
    Singlestepping == true;
  }

  if (Stepping == true)
  {
    digitalWrite(9, HIGH);
    delay(10);
    digitalWrite(9, LOW);
    delay(10);

    StepCounter = StepCounter ++; 1;

    if (StepCounter == DISTANCE)
    {
      StepCounter = 0;
      Stepping = false;
    }

    if (Singlestepping == true)
    {
      digitalWrite(9, HIGH);
      delay(10);
      digitalWrite(9, LOW);
      delay(10);

      StepCounter2 = StepCounter2 ++; 1;

      if (StepCounter2 == DISTANCE2)
      {
        StepCounter2 = 0;
        Singlestepping = false;
      }

    }

  }
}

Try this ( modifications at lines 39, 41, 54 and 56):

#define DISTANCE 384
#define DISTANCE2 24

int StepCounter = 0;
int StepCounter2 = 0;
int Stepping = false;
int Singlestepping = false;


void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);

  pinMode(3, INPUT);
  pinMode(4, INPUT);

}

void loop() {
  if (digitalRead(3) == LOW && Stepping == false)
  {
    Stepping = true;
  }

  else if  (digitalRead(4) == LOW && Singlestepping == false)
  {
    Singlestepping == true;
  }

  if (Stepping == true)
  {
    digitalWrite(9, HIGH);
    delay(10);
    digitalWrite(9, LOW);
    delay(10);

    //StepCounter = StepCounter ++; 1;

    if (++StepCounter >= DISTANCE)
    {
      StepCounter = 0;
      Stepping = false;
    }

    if (Singlestepping == true)
    {
      digitalWrite(9, HIGH);
      delay(10);
      digitalWrite(9, LOW);
      delay(10);

      //StepCounter2 = StepCounter2 ++; 1;

      if (++StepCounter2 >= DISTANCE2)
      {
        StepCounter2 = 0;
        Singlestepping = false;
      }

    }

  }
}

This is exactly the sort of thing the AccelStepper library makes easy - you can initiate a move whenever you want and it will happen automatically in the background (so long as you call the run() method frequently, ie in the
loop() function).

Have a look at the examples for AccelStepper library (you'll need to download it).