I'm trying to use a DC motor with pinion engaged to a rack gear, and have that motor move a distance, save the distance, delay, reverse, and travel back the same distance from where it started, delay, do it again. I want to start/stop the initial save with a button push, then from those saves, loop the motor movement.
I have considered using a Hall effect sensor or reed switch to count, but it seems a software interrupt or timing is easier using
millis(). I researched and found that
millis() cannot be reset, so I'm wondering if this is possible.
I haven't started a sketch, but I got this idea from the BlinkWithoutDelay example sketch included with the Arduino IDE. Like, have the motor positioned at "home" position, button push, start the timer, motor travels to end of work piece, stop the timer, save that forward distance traveled into a variable, reverse the motor, (at this point the timer would be at 0 again for the reverse travel) travel back to "home" save that reversed distance traveled into another variable with a button push, and then use these start/stop values in a loop. So I would save the values with a button pushes, then just loop that.
Or I'm thinking about putting an if or while button push outside the loop with a nested
counter++, eyeballing the motor travel, once it gets to where I want it, save those counts in variables, then using them in the loop to
analogWrite() to the motor.