cant get two steppers running in both directions

so i have been looking throught the site and cant find an answer so here goes. i am making a platform that has linear rails with one stepper on each axis. controlling with both joystick and buttons, joystick is to move into position and buttons are to move a set distance in a direction, my problem is thsat i cant get one on the steppers to turn both directions with the buttons, if i swith the drivers the problem goes to the other driver, same with swapping the motors. so i asses that the problem lies in the programing. no matter how i change the set up one of the motors wont go both direction. some one please help.

#include <Stepper.h>

const int stepsPerRevolution1 = 200;
const int stepsPerRevolution2 = 100;
Stepper myStepper1(stepsPerRevolution1, 3, 2);
Stepper myStepper2(stepsPerRevolution2, 6, 7);

#define stepPin2 7
#define dirPin2 6
#define stepPin 5
#define dirPin 4

const int up = 10;
const int down = 9;
const int left = 11;
const int right = 12;

const int readyled = 13;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output

void setup()
{
myStepper1.setSpeed(100);
myStepper2.setSpeed(100);

pinMode(up, INPUT);
pinMode(down, INPUT);
pinMode(left, INPUT);
pinMode(right, INPUT);

pinMode(stepPin , OUTPUT);
pinMode(dirPin , OUTPUT);
pinMode(stepPin2 , OUTPUT);
pinMode(dirPin2 , OUTPUT);
pinMode(SW_pin, INPUT);
pinMode(readyled, OUTPUT);

digitalWrite(SW_pin, HIGH);
digitalWrite(stepPin , LOW);
digitalWrite(dirPin , LOW);
digitalWrite(stepPin2 , LOW);
digitalWrite(dirPin2 , LOW);

}

void loop()
{
buttonState1 = digitalRead(up);
buttonState2 = digitalRead(down);
buttonState3 = digitalRead(left);
buttonState4 = digitalRead(right);

digitalWrite(readyled, HIGH);

if (analogRead(X_pin) >= 540) {
digitalWrite(readyled, LOW);
digitalWrite(dirPin, LOW); // move in this direction if we’ve moved less than 100 steps
digitalWrite(stepPin , HIGH); // set a HIGH value to our step pin, this turns the voltage on for that pin
delayMicroseconds(250);// let’s wait here for 50 milliseconds; note the units, this means 0.05s
digitalWrite(stepPin , LOW);// let’s set our step pin to false, this turns the voltage off for that pin and gives us the on/off cycle we need
delayMicroseconds(250);// wait another 50 milliseconds after which time we loop back to the beginning of the loop() loop
}
if (analogRead(X_pin) <= 450) {
digitalWrite(readyled, LOW);
digitalWrite(dirPin, HIGH); // move in this direction if we’ve moved less than 100 steps
digitalWrite(stepPin , HIGH); // set a HIGH value to our step pin, this turns the voltage on for that pin
delayMicroseconds(250);// let’s wait here for 50 milliseconds; note the units, this means 0.05s
digitalWrite(stepPin , LOW);// let’s set our step pin to false, this turns the voltage off for that pin and gives us the on/off cycle we need
delayMicroseconds(250);// wait another 50 milliseconds after which time we loop back to the beginning of the loop() loop
}
if (analogRead(Y_pin) >= 540) {
digitalWrite(readyled, LOW);
digitalWrite(dirPin2, LOW); // move in this direction if we’ve moved less than 100 steps
digitalWrite(stepPin2 , HIGH); // set a HIGH value to our step pin, this turns the voltage on for that pin
delayMicroseconds(2000);// let’s wait here for 50 milliseconds; note the units, this means 0.05s
digitalWrite(stepPin2 , LOW);// let’s set our step pin to false, this turns the voltage off for that pin and gives us the on/off cycle we need
delayMicroseconds(2000);// wait another 50 milliseconds after which time we loop back to the beginning of the loop() loop
}
if (analogRead(Y_pin) <= 450) {
digitalWrite(readyled, LOW);
digitalWrite(dirPin2, HIGH); // move in this direction if we’ve moved less than 100 steps
digitalWrite(stepPin2 , HIGH); // set a HIGH value to our step pin, this turns the voltage on for that pin
delayMicroseconds(2000);// let’s wait here for 50 milliseconds; note the units, this means 0.05s
digitalWrite(stepPin2 , LOW);// let’s set our step pin to false, this turns the voltage off for that pin and gives us the on/off cycle we need
delayMicroseconds(2000);// wait another 50 milliseconds after which time we loop back to the beginning of the loop() loop
}

//---------------------------------------------------------------------

if (digitalRead(up) == HIGH) {
digitalWrite(readyled, LOW);
myStepper1.step(stepsPerRevolution1);

}
if (digitalRead(down) == HIGH) {
digitalWrite(readyled, LOW);
myStepper1.step(-stepsPerRevolution1);

}
if (digitalRead(left) == HIGH) {
digitalWrite(readyled, LOW);
myStepper2.step(stepsPerRevolution2);

}
if (digitalRead(right) == HIGH) {
digitalWrite(readyled, LOW);
myStepper2.step(-stepsPerRevolution2);

}
}

newest.ino (4.34 KB)

If you are having problems making one motor turn both directions, why do you have so much code?

loop() should make one motor step 100 times in one direction. Then, it should make the same motor step 100 times in the other direction. Then, it should make the second motor step 100 times in one direction. Then, it should make the same motor step 100 times in the other direction. Then, it should end and repeat, or should encounter a while(1) {} block that makes it stop doing anything until reset.

If THAT makes the motors move properly, then the problem is in that mess of code you posted incorrectly. It not, the problem is in the hardware, and no amount of code editing is going to correct the problem.