I don't see many threads for this board, so I thought I'd post one.
By way of learning Arduino programming and helping my friend learn, too, I'm helping him automate a manual drilling machine. It has a rotary tool shaft that it moves on a linear slide, contolled by a hand cranked 1/4-20 allthread.
We've put a small stepper on it from a junked printer. The Stepper library is not meant for a Step/Dir control like the A4988, so I'm writing code for it.
We started with the Blink Without Delay sketch. millis() does not have the speed sufficient to move a stepper at any useful speed, so I am using micros() instead. It was fairly straightforward to convert it.
I found a mistake in Blink Without Delay - it does the math correctly to avoid the Rollover problem (millis() rolls over after about 49 days), but it mistakenly uses a long instead of an unsigned long for previousMillis. Simple enough to correct. Perhaps not much of a problem, although it would cause errors after half of the time to rollover, about 24 days. But for micros(), which rolls over in about 9 hours, it would cause it to break after about 4.5 hours.
Anyway, using micros() we've got a 200 step per turn motor running at 4 inches per second, which is all his drilling machine will take until we replace a few parts.
Here is a video we shot of it just moving back and forth every 5 seconds:
We tried using tone() to output steps, and it works great. But if the code were to crash, tone keeps sending, and the stepper would keep running. Using micros(), if the code crashes, the Arduino should stop sending Step signals. At least it is less likely to.
We'll be adding Home and End microswitches, a display, and a bunch of buttons to control various functions.