Hello,
There are many ways to do a timer and I have tried them all at one time or another.
You can use millis(), frameCount, Time & Date functions (see reference), counter, Java timer class, etc.
Slowing down frameRate us useful for slowing things down and I often use it for debugging or as required.
The default frameRate for draw() (stated in the reference) can be used as is or set and is used for animation or as required.
It is important to understand the flow of setup() and draw() before integrating a “timer” in your code.
Some good stuff here:
Example timer with millis():
You can add more println() statements to see value of variables as it progresses:
Timer < Expand for code
int whattimeisitnow;
int whattimeisitatstartofstopwatch;
int timepassedtoresetstopwatch = 1000;
//setup runs once
void setup()
{
whattimeisitatstartofstopwatch = millis();
println(whattimeisitatstartofstopwatch);
}
//draw loops 60 frames per sec
void draw()
{
whattimeisitnow = millis();
if (whattimeisitnow > whattimeisitatstartofstopwatch + timepassedtoresetstopwatch)
{
println("1000 ms have passed! Time elapsed (ms): ", whattimeisitnow);
whattimeisitatstartofstopwatch = millis(); //reset stopwatch and start over
}
}
:)