2 buttons executing different code

Hi, I'm looking to use two buttons in the same code, one button to move a motor forward and the other to reverse the motor. I've tried something like this: buttonState1 = digitalRead(buttonPin1); if (buttonState1 == HIGH) { ...... }

buttonState2 = digitalRead(buttonPin2); if (buttonState2 == HIGH) {.... }

However this did not work, when i press button 1 the motor turns forward very briefly then stops. Any suggestions on how to write it properly? Sorry if this is a fairly simple problem I am new to this stuff

This question should really be in the Programming Questions section, and you need to provide the complete code (not just an extract) and a description of what external components you have connected to the Arduino and how they are connected.

You need to take a look at finite state machines in the play ground.

Mark

A question, if you press the forward button and the release it that do you want to happen?

Mark