void loop() {
// [int2str] Unless you need millis() for other things, using it just
// [int2str] for this will cause the program to become larger for
// [int2str] questionable gains here. Also not fond of using a global
// [int2str] variable that's checked inside the function.
currentMillis = millis(); // save having to make multiple calls
updateScreen();
}
I had some thoughts about this. I said in the comment, "save having to make multiple calls," but honestly, the millis() function probably isn't much of a performance hog. How much slower is it than reading a variable, really? (I ask rhetorically, but I suspect you may actually know the answer.) The real reason I got started calling millis() like that at the beginning of my loop is that I may have several conditionals that rely on millis() and I don't want them comparing a different value, such as:
if (millis() - x > threshold1) // do some stuff
else if (millis() - y < threshold2) // do some stuff
else if (millis() / modulo = 0) // do some stuff
You get the idea. In that case, the elapsed time between the evaluation of the if and the evaluation of the else may cause cases that should be mutually exclusive not to be so, or cases that should always coincide not to. So I got in the habit of tagging millis() at the beginning of each loop and just referring to that variable most of the time, except for cases where real-time response was specifically required.
As for the global variables... this is one of my WORST habits as a programmer, and it always has been. I kick myself about it all the time because ... well, I have a degree in CS, although I have never coded professionally. So I don't even have the excuse of ignorance. But the flip-side is that if a given function would always take the same five parameters, and would never take any other parameters, what's the point of declaring those as local variables and then passing them to a function? Why not just declare them global and refer to them?
The situation is exacerbated, I think, by the Arduino environment, which, as far as I can tell, requires any variable that outlasts a single loop() to be global. So you are required to make a bunch of global variables, at which point, it's easy to get lazy and just make a bunch more.