Hello all,
I am working on a project where I have to make a motor move for a certain number of steps then stop. I know how to make it move but I dont know how to make it stop. it just keeps going on and on, can someone help me make it stop?
Your code starts in mode==2 and thus moves downward repeatedly. It never changes to any other mode. If you only want to move 5000 steps once you should probably switch to mode==3 as soon as you initiate the downward move.
You don't seem to have any code to change the mode.
My guess is that you need to create a checkMode() function and call it from loop(). Then you will find that it doesn't get called while a motor is moving due to the WHILE loop in the moveup() and movedown() functions. That can be solved by moving the call to motor.run() into loop() and dispensing with the WHILEs in the functions.