One of the SimpleTimer libraries such as this one by Marcello Romani (which I mention because I have used it; there are others). It creates a timers object that has 10 (in this case) software-based timers with a variety of operating modes (run once, run x times, run forever, e.g.).
The basic idea (for a 1-LED example) is that you write a function (known as a "callback" to step up the brightness of an LED by one step. Let's call it stepUp()
.
You write another callback function to turn off the LED and start a timer that will call stepUp()
at whatever interval you choose for as many times as it takes to reach 100%. Let's call this one cycleLED()
.
In your setup()
, you'll start another timer that will call cycleLED()
as often as you want that process to run - every 1200 mSec in this case - and for as many times (or forever) as you choose.
In your loop() function, you'll need a call to your timer object's .run() function as often as possible - that is what makes the timers work, and it is the timers that will call your callback functions to make your LEDs behave as you want them to.
So far, we one fading-up LED, and I'd recommend you implement this much at first.
There are two ways to go from here. You can write the above pair of callbacks for each LED, but they will be nearly identical and why write maintain the same code, several times over? Or you can use another feature of the library - a pointer-to-void argument to the callback function - in which you can pass any value, such as an LED's number or address, so that one callback could operate on the specified LED.
If you go with first option, your setup()
function will need to to start 5 timers, one for each cycleLED()
function (which would need to have distinct names, of course), and those timers start-times will need to be staggered.
With the second option, you would write a third callback, allCycles()
that sequences the starts of each cycleLED()
in turn. In this case, your setup()
function would only need to start a timer to repeatedly call allCycles()
.
There's a lot there, if these are new concepts. If so, it will be a lot easier to experiment with the SimpleTimer library doing something trivial at first, like flashing (not fading) one LED, then several LEDs, until this way of coding timed events feels less foreign.
millis()
and the current brightness value to compute the next needed jump or reduction in the brightness