I don't understand why you are doing an analogRead() for direction. What are you using to control the direction? I would expect a 2-way switch and if so I would be using digitalRead(). You can use digitalRead() with analog pins.
You have a big chunk of commented out code and I don't know what it is intended to be - it seems to be a complete second program.
...R