Controlling Stepper motor with 4 buttons

Hi Everyone,

I am doing a project in which I am trying to control several different motions of the motor using an Arduino and buttons. I have written down my program but it is not working. I understand the buttons are momentarily push buttons but I cannot figure out how to operate them as Maintained Push buttons.

The project is simple. There are 4 buttons and each button will activate 4 different motions. If one button is pressed twice, the motor turns OFF. The motor is connected to a linear actuator so it always turn ON and OFF at one end of the actuator.

I have posted my program below. Can someone help me change it a bit or advise me on how to make it work?

Thanks,

Main Program.txt (2.57 KB)

You need to do stuff when the button becomes pressed not when it is pressed. So you get the value of the button now and compare it with the value you read last time. When they are different you have a button press or release event. Use that to set / clear a Boolean variable that then controls your stuff.