// Blink LEDs at independent intervals 

unsigned long interval[] = {300, 700, 900, 2100, 3150}; // events *** SEE welcome() TIMING CHART ***
byte ledPin[] = {2, 4, 6, 8, 10}; // pins for the LEDs
#define EVENTS sizeof(ledPin)/sizeof(ledPin[0]) // find the size of the pin array
unsigned long oldTime[] = {0, 0, 0, 0, 0}; // clear event timers (start at zero time)
int counter;

void setup() {
  Serial.begin(115200); // for the serial monitor
  welcome(); // call the "welcome" screen with the timing diagram
}

void loop() {

  for (int i = 0; i < EVENTS; i++) { // cycle through all events array
    if (millis() - oldTime[i] >= interval[i]) { // compare intervals to time difference
      oldTime[i] = millis(); // event interval 'i' has occurred, set new event i zero time

      // event interval for each (ledPin[]) has been met...
      blinkLED (i); // call the function to blink the 'i'th LED

      if (counter > 79) { // serial monitor formatting
        counter = 0;
        Serial.println();
        Serial.print("interval[#] ---> ");
      }
      counter++;
      // Serial.print(ledPin[i]); // print the event pin number
      Serial.print(i); // print the single event array number
    }
  }
}

void blinkLED (int thisLED) {
  digitalWrite(ledPin[thisLED], HIGH);
  delay(10);
  digitalWrite(ledPin[thisLED], LOW);
}

void welcome() {
  Serial.println("Each character on this timing graph represents 100ms.");
  Serial.println("interval[0] RED LED every  300ms |--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*");
  Serial.println("interval[1] ORG LED every  700ms |------*------*------*------*------*------*------*------*------*");
  Serial.println("interval[2] YEL LED every  900ms |--------*--------*--------*--------*--------*--------*--------*");
  Serial.println("interval[3] GRN LED every 2100ms |--------------------*--------------------*--------------------*");
  Serial.println("interval[4] BLU LED every 3150ms |-------------------------------*------------------------------*");
  Serial.print("interval[#] ---> ");
}