dannysprogis:
So the reason I am not seeing it on my bench testing is because I am only waiting a few minutes before I start the rotation and time_now doesn't have much of a chance to drift from the milli count ? and after waiting overnight it does?
That is essentially correct, after 8 hours millis() will have a value of 28,800,000. With a delay of 75922mS per step it would take around 379 steps before you started seeing the delay between steps.
Is the solution as simple as making time_now = millis() at the beginning of each void iteration?
No, then millis() would never be >= time_now + DelayBetweenSteps.
You need to initialize time_now when the alarm time has been reached, that will synchronize it with the current millis() value.
if (DoneSelectedRotation == true) //only check the alarm if alarm time has not been reached
{ //this prevents this code from executing more than once
if (now.hour() == Alarm_Hour) // check alarm
{
if (now.minute() == Alarm_Minute)
{
Serial.println("The time is now!"); //if alarm time
DoneSelectedRotation = false;
time_now = millis() - DelayBetweenStep; //initialize time_now so that stepper motor steps immediately
}
}
}
I would also change the if statement that is checking millis() against the timer, the way you have it written will eventually give incorrect results. You are unlikely to notice it in your application, but at around 50 days of runtime the millis() counter overflows from its maximum value to 0, and starts counting up from 0 again. Slightly before this time, the value of time_now + DelayBetweenStep will overflow, resulting in a very low number, while millis() is still near its maximum value, making the if statement true when it should not be.
if (millis() >= time_now + DelayBetweenStep)
{
time_now += DelayBetweenStep;
The convention way of writing the if statement would be like this, although normally time_now would be set to millis() inside the if statement. Incrementing it by DelayBetweenStep will work, and avoids a slight drift in the time interval when you are a millisecond or two late getting to the if statement.
if ( (millis() - time_now) >= DelayBetweenStep) {
time_now += DelayBetweenStep;
...
}
I would also change DelayBetweenStep to an unsigned long, I don't see anywhere you are using it that needs it to be a float, and millis() timing is all does as unsigned integer math.