// https://wokwi.com/projects/403520059001187329
// https://forum.arduino.cc/t/late-night-switch-case-confusion/1281147

// version #42

# include <ezButton.h>

const byte ledPin[] = {13, 12, 14};
ezButton button[] = {2, 4, 5};
const byte nLEDs = sizeof ledPin / sizeof *ledPin;

void setup() {
  for (byte ii = 0; ii < nLEDs; ii++) {
    button[ii].setDebounceTime(25);
    pinMode(ledPin[ii], OUTPUT);
  }
}

void loop() {
  static byte ledState = nLEDs;
  static byte iLoop;

  if (button[iLoop].loop(), button[iLoop].isPressed())
    ledState = ledState == iLoop ? nLEDs : iLoop;
  digitalWrite(ledPin[iLoop], ledState == nLEDs ? LOW : (ledState == iLoop ? HIGH : LOW));

  iLoop++; if (iLoop >= nLEDs) iLoop = 0;
}


/* version #39


# include <ezButton.h>

const byte ledPin[] = {13, 12, 14};
ezButton button[] = {2, 4, 5};
const byte nLEDs = sizeof ledPin / sizeof *ledPin;

void setup() {
  for (byte ii = 0; ii < nLEDs; ii++) {
    button[ii].setDebounceTime(25);
    pinMode(ledPin[ii], OUTPUT);
  }
}

void loop() {
  static byte ledState = nLEDs;

  for (byte ii = 0; ii < nLEDs; ii++)
    if (button[ii].loop(), button[ii].isPressed())
      ledState = ledState == ii ? nLEDs : ii;

  for (byte ii = 0; ii < nLEDs; ii++)
    digitalWrite(ledPin[ii], ledState == nLEDs ? LOW : (ledState == ii ? HIGH : LOW));
}

*/