Stepper Motor Button Control - Can Someone Check My Logic Please.

I have a small bipolar stepper (like a head motor in a floppy drive) being driven by a DRV8834 board (the low voltage brother to A4988). I’ve made a simple sketch to test the principle of running the motor one way upon the press of a momentary switch, then back again on a second press. If I take out the button components of the sketch, I can make the motor run back and forth endlessly, so the stepper hardware is doing it’s job. Similarly, I can make a separate sketch of the button doing it’s thing, toggling an LED on and off. But when I try to marry the two, the motor just sits there doing nothing (although it feels energised). I’ve tried ‘for/else’ loops, boolean and just integers for the button state and stepper state. At one point I did get a button press to run the motor out and back , but that isn’t what I need. Press (1) - motor out. Press (2) - motor in. Return to beginning. Couldn’t be more simple, could it?

Can someone with more experience cast an eye over my code and tell me where my logic is failing please?

Stepper_Test.ino (1.69 KB)

More members will see your code if posted properly. Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.