for you, you might have a keen understanding of the numbers you see on the Serial output. But, you may also benefit from (as others may too) giving a little description of what all the numbers mean!
something like this:
int try_process ()
unsigned long now = millis();
static unsigned long lastMillis = 0;
if (now - lastMillis > 2000UL)
unsigned long functionMillis = millis();
Serial.printlnf("Currrent millis() = %u", functionMillis);
Serial.printlnf("Entered function at %u millis", now);
Serial.printlnf("Functions took %u milliseconds", functionMillis - now);
Serial.printlnf("Last ran function at %u millis", lastMillis);
Serial.printlnf("Total elapsed millis betweeen calls = %u", now - lastMillis);
lastMillis = now;
if ((now - lastMillis) > my_delay)
// return 1; //eliminate as superfluous
As a side note, you may also benefit from using more meaningful variable names… and meaningful scope. in my edited code, I think that
lastMillis is only used in
try_process() and make that known by keeping it within the scope of that function. Making a variable global implies that it may be affected/used in multiple places. That may be the case in your (yet to be disclosed) code, but worth mentioning nonetheless.
To me, it looks like one of your unsigned subtractions is wrapping to a number less than zero… but I don’t know what number I am looking at!!!