As a novice I'm unclear what benefit there is in declaring a variable to define the current time, instead of simply always using plain 'millis()'?
Such as in this fragment of my code:
void loop()
{
unsigned long currentMillis = millis();
// If time for a keep-alive photo has been reached
if (currentMillis - previousMillis >= interval)
{
// etc
I could instead write the following, which to me seems more informative, as well as avoiding an extra variable:
void loop()
{
// If time for a keep-alive photo has been reached
if (millis() - previousMillis >= interval)
{
// etc
Because the value of millis may change between when you read it in the condition, and when you use it to update previousMillis in the conditional code block.
If you want multiple events to synchronize with each other, then you need to use the same "millis()" value for all of those events. If you call "millis()" for each event, then the synchronization may slip slightly for each loop, and on the long run things may go completely out of synchronization and cause unwanted behaviour.
And calling millis() is also creating a variable, that variable then gets put into the equation, but you are not even saving on RAM or even on program space for that matter. The variable space has already been created, and it just gets copied (rather than a new call to millis() ) Also if the variable just gets used once, as in you snippet (without the extra conditional assignment) the extra assignment may get optimized out if it is unnecessary. say
unsigned long currentMillis = millis();
unsigned long interval = 5000;
if (currentMillis - previousMillis >= interval)