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;
}
}
}