hey
we are trying to do 2 buttons for the same motor if button 1 pressed move forward … else stop … and then if button 2 pressed move backward else stop
here is the code we are using but it doesn’t work well :
Its a logic error, if you hold down button 1, then that will set the motor to 1, then since button 2 is not held down it will go to that else which will set it back to 0.
Because you have two separate if…else statements, if the reverse button isn’t held down, the output will be zero regardless of the forward button’s state.
Also, this:
if (condition);
has no code to execute because of that trailing semicolon. An “if” will execute the statement immediately after it up until a semicolon, or if you put the code inside {curly braces}, it will execute everything in the first set of braces. If statements don’t need any additional semicolons.
Alan Anderson let me know that I messed up. I misread your code snippet: I didn’t realize that the reverse button would drive the motor in reverse… (crosses eyes) I really need some more sleep.
Let me know if you have any more questions or problems.