/*
The profiles-array has 13 rows and 9 values per row, but is restricted to 2x4=8 profile durations (changes to ON + changes to OFF),
the last value of each row array is set to 0 to trigger repetition of the pattern.
(the last value is 0 automatically, as long as it is not overwritten)
*/
int profiles[13][9]={{9,1},{1,2},{10,10},{1,1,1,3,1,8},{1,1},{1,1,1,1,1,10},{1,1,1,1,1,1,1,13},{4,4},{1,3},{4,4},{4,4},{1,1,1,7},{5,1}};
// resp. Breskens, Westkapelle, Noorderhoofd, Westerschouwen, Verklikker, Westhoofd, Goeree, Kwade Hoek,
// Maasvlakte, Maasmond hoog, Maasmond laag, Scheveningen, Noordwijk aan zee, patterns.
long targets[13];
int actual[13];
bool lightStatus[13];
int leds[13];
void setup() {
for (int r=0; r<13; r++) {
targets[r] = random (1000,5000); // random start for each light between 1 and 5 seconds.
/*
The profile starts after a random time between 1 and 5 seconds with the light off.
The actual period is set to 7. When the start target is reached, actual[] increases by 1 and becomes 8.
Period 8 is intentionally set to zero for all lights, hence the actual[] will upgrade to 0, the light will
switch to on and the first real period will start.
*/
actual[r] = 7;
lightStatus[r] = false; // turn all lights off.
leds[r] = r + 2; // use pins 2 thru 14(=A0).
pinMode (leds[r],OUTPUT);
}
}
void loop() {
for (int x=0; x<13; x++) {
if (millis() >= targets [x]) { // if the target has been reached, increase the counter.
actual[x] = actual[x] + 1;
if (profiles[x][actual[x]] == 0) {
actual[x] = 0; // reset the counter if a zero has been encountered.
}
targets[x] = targets[x] + (profiles[x][actual[x]])*1000; // increase the target with the next profile value (in milliseconds).
lightStatus[x] = !lightStatus[x]; // toggle the light status.
digitalWrite (leds[x], lightStatus [x]);
}
}
}