Hi, I am using p5 js and I am trying to have some code execute every 10 seconds. I am having trouble finding the solution. Thanks.
1 Like
2 Likes
1 Like
I just realized that what I meant was to have a 10 second wait then have code executing for ten seconds, then not execute for 10 seconds and repeat.
Hello,
Ideally you should make a flowchart.
To get you started:
-
What time is it at start? Do this in setup()
timeLast = millis() -
What time is it now? You are now in draw()
timeNow = millis() -
What is elapsed time?
timeElapsed = timeNow - timeLast -
Is elapsedTime 10s or more?
Do something!
and reset timer to start over when this condition is met
timeLast = millis() -
Rinse and repeat
:)
2 Likes
is elapsedTime >= 10s (= 10000 ms)
1 Like