Need assistance with timing! [millis()]

I provided a simple example:

int whattimeisitnow;
int whattimeisitatstartofstopwatch;
int timepassedtoresetstopwatch = 1000;

//setup runs once
void setup()
  {
  whattimeisitatstartofstopwatch = millis();  
  }

//draw loops 60 frames per sec  
void draw()
  {
  whattimeisitnow = millis();
  if (whattimeisitnow > whattimeisitatstartofstopwatch + timepassedtoresetstopwatch)  
    {
    println("1000 ms have passed!");
    whattimeisitatstartofstopwatch = millis();                     //reset stopwatch and start over
    }
  }

This is a very basic timer that is very common; I just added descriptive variable names.

I would like you to explain to me how it works and then try writing it from scratch.
I do this often (code from scratch) as an exercise to work my brain.

You can also add println() statements to see what is going on with code.
Keep in mind that millis() is constantly updating in the background with the passage of time and the variables will update.

https://processing.org/reference/millis_.html

:)

2 Likes