Function over many cycles of loop()

Here's another way to do it:

There are lots of answers to this, pick the one that you like best or invent your own.