I wonder if it works better if you say:
else if (val == 2)//input of 2 makes it move backwards for 1 second
-br