johnwasser:
Factoring out the common code in your state machine makes the code more readable and easier to modify:
now i tested the code with out powering the motor and it work fine but when i plug the motor when i press the button it change the state but it dose not exit it(the IR stop lighting up) maybe it is a power problem?
BTW i am using l293d to connect the motors