Stepper motor attached with 3 micro switches to do 3 different commands

Hi all,

Im having trouble telling my stepper motor to go clockwise continually until it hits a micro switch that then turns it anticlockwise to a home micro switch which turns it off.

3 different micro switches are attached to the Arduino along with the STEP and DIR pin from the easy driver. The easy driver has 12V going through it also the 4 cables from the motor.

Im trying to use the micros switches as a toggle switch which I believe is achieved with the first 2 lines of code under void loop.

I am able to run the motor continually with no switches on the circuit or the code that is attached now but when I try to put switches on and the code it doesn’t want to play ball

The first of the micro switches i’m using is to start the motor rotating clockwise.
The second is to stop the motor for 1 second and then is to revers the motor rotating anticlockwise.
Finally the third is to stop the motor.

If anyone knows where my code is going wrong or what I need to do in order to make this system function as I need it would be greatly appreciated.

components:

stepper motor JK42hm34-1334

A3967 easy driver

Micro switches

Dazzle_Return.ino (1.68 KB)