- a program which also displays the number of objects which passed in the last minute.
- I would like the number to refresh about every second.
You could achieve that with a circular buffer of samples acting as a FIFO, each sample covering one second, sixty samples in the buffer making up the total for the past minute.
Accumulate the number of objects in a counter. Once per second, push the counter value into the FIFO and then reset the counter. Pushing the new value in will push the oldest value out of the FIFO. The sum of the entries in the FIFO gives you the total for the past minute.
To avoid having to walk the contents of the FIFO adding them up every second, you can keep a running total which is incremented with the value pushed into the FIFO and decremented with the value pushed out.
If the counters are going to be large and an exact total over the minute isn't important you can get very similar behaviour much more simply just using a single accumulator. Each time you get a new sample you calculate a weighted average of the accumulator and the new sample, and store that in the accumulator. In effect you get a decaying average of the recent samples, and your weighting determines how quickly it decays.