Controlling two steppers with two switches

Hi,

I'm trying to control two stepper motors to get them to operate in a square sort of fashion using two buttons.

Basically something like

Button press Next Stepper Motor1 moves X steps

Wait for next input

Button press Next Stepper Motor2 moves X steps Wait for next input

Button press Next Stepper Motor1 moves back X steps

Button press Next Stepper Motor2 moves back X steps

Repeat, but also do the reverse at any point via a back button. I'm not sure what sort of structure to use to do this, perhaps a case statement?

Thanks

Finite state machine. Every button press moves to a next (or previous) state and the system reacts accordingly.

You will have to keep track of the stepper's actual position (so you can use absolute positions for your states and move accordingly). Also you'll have to add some kind of "home" limit switch so upon startup the stepper can home itself, and you have a known position to start from.

I agree with @wvmarie.

These links may also be helpful Stepper Motor Basics Simple Stepper Code

...R