Two motors, two buttons, a few questions

Thanks for reading. This program's aim is to run two Nema 17 stepper motors with Easy Drivers. Goal is to run each motor independently when respective button is pushed. I would like to use each motor to turn bot left and right when individual button is pressed. Circuit has two buttons however when each button is pressed by itself, both motors run regardless of which button is pulling Vdd low.

Please see code below:

#define DISTANCE 3200

int StepCounter = 0;
int Stepping = false;

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

pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(6, LOW);
digitalWrite(7, LOW);

pinMode(3,INPUT); //button for motor 1
pinMode(5,INPUT); //button for motor 2

}

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

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

StepCounter = StepCounter + 1;

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

if (digitalRead(5) == LOW && Stepping == false)
{
Stepping = true;
}

if (Stepping == true)
{
digitalWrite(7, HIGH);
delay(1);
digitalWrite(7, LOW);
delay(1);

StepCounter = StepCounter + 1;

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

}

Yep, looks like pressing either button sets "Stepping" to true.

Before posting, please read the "How to use this forum" post and follow the directions.

Please elaborate. Your response is not clear. Thanks

You need a different "Stepping" for each motor, like Stepping1 and Stepping2.

Thanks Edge for the helpful feedback :0) Good catch!

I reckon you will soon find that delay() gets in the way of a responsive program because it blocks the Arduino from doing other things. Have a look at the second example in this Simple Stepper Code. It uses millis() and micros() for non-blocking timing.

Also, your program seems to set stepping to true and leave it like that until the movement completes. That means there is no means to stop the movement before it completes.

...R
Stepper Motor Basics
Planning and Implementing a Program

I definitely recommend starting with AccelStepper library, it handles speed ramping and makes it
fairly simple to run motors independently - you do have to ensure the run() method for each motor
is called in loop() and get rid of all delay() calls in your code so loop runs frequently, but that's what
you should be doing anyway.