I am trying to reverse the direction of a stepper motor. The stepper motor drives a scanner head and when it gets to the end, I want it to reverse direction. I have some photo interrupters that trigger when the signal is interrupted but how do I make it switch direction when they are triggered? Do I use a flip-flop and if so what type. I am driving the stepper motor with a H-bridge that is controlled from an Arduino but I would prefer to switch the direction with hardware instead of programming it to reverse when it gets to the end. So what type of flip-flop do I use had how do I wire it? I have a bipolar 4 wire stepper motor.
Code to make the stepper motor move forward:
#include <Stepper.h>
#define STEPS 96
#define D0 3
#define D1 4
#define D2 5
#define D3 6
const int enab1 = 2;
const int enab2 = 7;
Stepper stepper(STEPS, D0, D1, D2, D3);
void setup() {
digitalWrite(enab1, HIGH);
digitalWrite(enab2, HIGH);
stepper.setSpeed(600);
stepper.step(7596);
digitalWrite(enab1, LOW);
digitalWrite(enab2, LOW);
}
void loop() {
}
Thanks.