Here's my problem. I have a device (ozone generator) which produces 10g of ozone per hour, or 2.77778 milligrams per second (I think). I need to be able to control the production per hour by pulsing the machine on and off to achieve an even rate.
How do I figure out the required rate of pulsing?
So if I can figure out the required amount of seconds to produce the required amount of ozone, how do I evenly distribute those seconds over an hour?
Let's pick an example: I want to generate $3.1$ grams of ozone per hour. This is $0.31$ of the full-time output.
What we'll do is, for each second, accumulate $0.31$ into an 'accumulator' and then when that value reaches $1$, we'll emit for a second, subtract $1$, and continue. So:
Further reading: Bresenham's Line Algorithm, Dithering
Alternatively: since we want $0.31$ of the time to be emitting, that's $1/3.226$ of the time, so we can do "wait 2.226 seconds, emit for one second" over and over and that works too.