#include <Toggle.h>                 // https://github.com/Dlloydev/Toggle

const byte redButtonPin = A0;
const byte blueButtonPin = A1;

const byte redLedPins[] = {8, 9, 10, 11};
const byte redLedPinsCount = sizeof redLedPins / sizeof * redLedPins;
byte redIndex = 0;

const byte blueLedPins[] = {2, 3, 4, 5};
const byte blueLedPinsCount = sizeof blueLedPins / sizeof * blueLedPins;
byte blueIndex = 0;

Toggle redButton, blueButton;


void introAnimation() {
  // blue lights ON
  const unsigned long speed = 50;
  // red lights ON
  for (int8_t i = redLedPinsCount - 1; i >= 0 ; i--) {
    digitalWrite(redLedPins[i], HIGH);
    delay(speed);
  }
  for (int8_t i = blueLedPinsCount - 1; i >= 0 ; i--) {
    digitalWrite(blueLedPins[i], HIGH);
    delay(speed);
  }
  // blue lights OFF
  for (int8_t i = 0; i < blueLedPinsCount; i++) {
    digitalWrite(blueLedPins[i], LOW);
    delay(speed);
  }
  // red lights OFF
  for (int8_t i = 0; i < redLedPinsCount; i++) {
    digitalWrite(redLedPins[i], LOW);
    delay(speed);
  }
}

void setup() {
  for (byte i = 0; i < redLedPinsCount; i++) pinMode(redLedPins[i], OUTPUT);
  for (byte i = 0; i < blueLedPinsCount; i++) pinMode(blueLedPins[i], OUTPUT);
  redButton.begin(redButtonPin);
  blueButton.begin(blueButtonPin);

  introAnimation();
}

void loop() {
  redButton.poll();
  if (redButton.onPress()) { // red button pressed

    // flip state of the LED at the index
    if (digitalRead(redLedPins[redIndex]) == HIGH) {
      digitalWrite(redLedPins[redIndex], LOW);
    } else {
      digitalWrite(redLedPins[redIndex], HIGH);
    }

    // increase the index
    redIndex++;

    // don't overflow
    if (redIndex >= redLedPinsCount) redIndex = 0;
  }

  blueButton.poll();
  if (blueButton.onPress()) { // blue button pressed

    // flip state of the LED at the index
    if (digitalRead(blueLedPins[blueIndex]) == HIGH) {
      digitalWrite(blueLedPins[blueIndex], LOW);
    } else {
      digitalWrite(blueLedPins[blueIndex], HIGH);
    }

    // increase the index
    blueIndex++;

    // don't overflow
    if (blueIndex >= blueLedPinsCount) blueIndex = 0;
  }
}