Stepper Control Code Help

Hi All,
Just picked up some L293D’s and have a 4wire stepper motor from a DVD rom. So far I have found and modified some code to run the motor forward then backward. I’ve essentially declared two motors so that I may reverse the direction. I know there’s a better way. What would be a better way of doing what I’ve done?

#include <Stepper.h>
 
int in1Pin = 12;
int in2Pin = 11;
int in3Pin = 10;
int in4Pin = 9;

int curStep = 0;
int maxStep = 300;

Stepper motorForward(200, in1Pin, in2Pin, in3Pin, in4Pin);  
Stepper motorBackward(200, in4Pin, in3Pin, in2Pin, in1Pin);  
 
void setup()
{
  pinMode(in1Pin, OUTPUT);
  pinMode(in2Pin, OUTPUT);
  pinMode(in3Pin, OUTPUT);
  pinMode(in4Pin, OUTPUT);

  motorForward.setSpeed(50);
  motorBackward.setSpeed(50);
}
 
void loop()
{
  while(curStep < maxStep)
  {
    int steps = 1;
    motorForward.step(steps);
    curStep++;
  }

  while(curStep > 0)
  {
    int steps = 1;
    motorBackward.step(steps);
    curStep--;
  }
}

Thank You, John

well I've found a whole bunch of ways to not make it better. a bunch of ways to trigger errors on compile, but no way of making it better. Guess I've already found the best way. Awesome!

What you have is certainly practical. However if you give negative numbers, such as

motorForward.step( - steps);

you should find that it goes backwards

...R

Very strange that that works. I'm astounded it actually does work. I figured at best it would see my int steps = 1; and make it zero.

Thank You!!

bumba000: I'm astounded it actually does work.

I'm astounded that you are astounded :)

RTFM

...R

Nice link! It's incredible all the results that google barfs up for terms like "reversing stepper arduino" or "arduino stepper direction" etc... but not the page that you linked to. Nice chat Robin2. Thank You..