#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

bool gameOn = false;
bool selected = true;
bool down = false;

int timetoturnoff = 0;

int buttonState = 0;

#define BUTTON_MUL 2
const uint8_t controlPins[] = { 4, 3, 2 };
#define COM A0

#define LED0 5
#define LED1 6
#define LED2 7
#define LED3 8
#define LED4 9

bool led_0_active = false,
  led_1_active = false,
  led_2_active = false,
  led_3_active = false,
  led_4_active = false;

bool wait_1 = false;

int buttonState_0 = 0,
  buttonState_1 = 0,
  buttonState_2 = 0,
  buttonState_3 = 0,
  buttonState_4 = 0,
  buttonState_5 = 0;

// LCD Chars

byte title_0[] = {
  B11111,
  B10001,
  B10101,
  B10101,
  B10001,
  B10101,
  B10001,
  B11111
};

byte title_1[] = {
  B11111,
  B10001,
  B10101,
  B10101,
  B10001,
  B10101,
  B10001,
  B11111
};

byte title_2[] = {
  B11111,
  B10001,
  B10101,
  B10101,
  B10001,
  B10101,
  B10001,
  B11111
};

byte title_3[] = {
  B11111,
  B10001,
  B10101,
  B10101,
  B10001,
  B10101,
  B10001,
  B11111
};

byte title_4[] = {
  B11111,
  B10001,
  B10101,
  B10101,
  B10001,
  B10101,
  B10001,
  B11111
};

byte title_5[] = {
  B11111,
  B10001,
  B10101,
  B10101,
  B10001,
  B10101,
  B10001,
  B11111
};

byte title_6[] = {
  B11111,
  B10001,
  B10101,
  B10101,
  B10001,
  B10101,
  B10001,
  B11111
};

byte title_7[] = {
  B11111,
  B10001,
  B10101,
  B10101,
  B10001,
  B10101,
  B10001,
  B11111
};

// Frame 1
byte explode_0_0[] = {
  B00000,
  B00001,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

byte explode_1_0[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00001,
  B00000
};

byte explode_2_0[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

byte explode_3_0[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

byte explode_4_0[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

byte explode_5_0[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00001,
  B01011,
  B11100
};

byte explode_6_0[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B10000,
  B10100,
  B11000,
  B00111
};

byte explode_7_0[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

// Frame 1
byte explode_0_1[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

byte explode_1_1[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B11001
};

byte explode_2_1[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B01000,
  B00100,
  B10001
};

byte explode_3_1[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

byte explode_4_1[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00001,
  B00111
};

byte explode_5_1[] = {
  B00101,
  B11010,
  B11110,
  B01101,
  B10011,
  B11011,
  B11100,
  B11100
};

byte explode_6_1[] = {
  B00000,
  B00100,
  B00010,
  B00011,
  B10001,
  B01100,
  B11000,
  B00011
};

byte explode_7_1[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B10000,
  B10000,
  B11000,
  B11100
};

// Frame 2
byte explode_0_2[] = {
  B00000,
  B00001,
  B00011,
  B00011,
  B00010,
  B00010,
  B00010,
  B00011
};

byte explode_1_2[] = {
  B11111,
  B11100,
  B10000,
  B00000,
  B00000,
  B00000,
  B00001,
  B11111
};

byte explode_2_2[] = {
  B11111,
  B00011,
  B00001,
  B00000,
  B00000,
  B01000,
  B00100,
  B10011
};

byte explode_3_2[] = {
  B10000,
  B11000,
  B11100,
  B11100,
  B01100,
  B01100,
  B01100,
  B01100
};

byte explode_4_2[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00011,
  B11111,
  B01111
};

byte explode_5_2[] = {
  B11111,
  B11110,
  B11110,
  B01111,
  B11111,
  B11111,
  B11111,
  B11100
};

byte explode_6_2[] = {
  B00111,
  B00110,
  B00011,
  B00011,
  B10111,
  B01100,
  B11000,
  B00111
};

byte explode_7_2[] = {
  B11000,
  B11000,
  B11000,
  B10000,
  B10000,
  B10000,
  B11000,
  B11111
};

// Skull Emoji
byte skull_0[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00010
};

byte skull_1[] = {
  B00111,
  B11100,
  B10000,
  B10000,
  B10000,
  B10000,
  B11110,
  B10100
};

byte skull_2[] = {
  B11100,
  B00111,
  B00001,
  B00001,
  B00001,
  B00001,
  B01111,
  B00101
};

byte skull_3[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B01000
};

byte skull_4[] = {
  B00101,
  B00111,
  B00000,
  B00000,
  B00011,
  B00010,
  B00001,
  B00000
};

byte skull_5[] = {
  B10001,
  B01100,
  B11100,
  B01011,
  B01100,
  B10011,
  B00000,
  B00000
};

byte skull_6[] = {
  B10001,
  B00110,
  B00111,
  B11010,
  B00110,
  B11001,
  B00000,
  B00000
};

byte skull_7[] = {
  B10100,
  B11100,
  B00000,
  B00000,
  B11000,
  B01000,
  B10000,
  B00000
};

#define WOKWI true
// If this is running in wokwi, some different code will run

#ifdef WOKWI

// Wokwi doesn't have a proper analog simulation, so the relays behave differently

// IRL, the last relay needs to be connected to the arduino's VIN pin, not the ground pin

void updateLights(void) {
  digitalWrite(LED0, LOW);
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, LOW);
  digitalWrite(LED0, led_0_active == false ? LOW : HIGH);
  delay(10);
  digitalWrite(LED0, LOW);
  digitalWrite(LED1, led_1_active == false ? LOW : HIGH);
  delay(10);
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, led_2_active == false ? LOW : HIGH);
  delay(10);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, led_3_active == false ? LOW : HIGH);
  delay(10);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, led_4_active == false ? LOW : HIGH);
  delay(10);
  digitalWrite(LED4, LOW);
  return;
};

#else

void updateLights(void) {
  digitalWrite(LED0, led_0_active == false ? LOW : HIGH);
  digitalWrite(LED1, led_1_active == false ? LOW : HIGH);
  digitalWrite(LED2, led_2_active == false ? LOW : HIGH);
  digitalWrite(LED3, led_3_active == false ? LOW : HIGH);
  digitalWrite(LED4, led_4_active == false ? LOW : HIGH);
  return;
};

#endif

void setup(void) {
  Serial.begin(115200);
  pinMode(LED0, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  for (int i = 0; i < 3; i++) {
    pinMode(controlPins[i], OUTPUT);
  };
  pinMode(COM, INPUT);
  updateLights();
  lcd.init();
  lcd.noBacklight();
  lcd.noBlink();
  randomSeed(analogRead(A1) + analogRead(A2) + analogRead(A3));
  return;
};

#ifdef WOKWI

float readMux(unsigned char channel) {
  for (unsigned char i = 0; i < 3; i ++) {
    digitalWrite(controlPins[i], HIGH);
  };
  delay(3); // Delay to read
  for (unsigned char i = 0; i < 3; i ++) {
    digitalWrite(controlPins[i], channel >> i & 1);
  };
  delay(5); // Delay to read
  return analogRead(COM);
};

int readDigitalMux(unsigned char channel) {
  for (unsigned char i = 0; i < 3; i ++) {
    digitalWrite(controlPins[i], HIGH);
  };
  delay(3); // Delay to read
  for (unsigned char i = 0; i < 3; i ++) {
    digitalWrite(controlPins[i], channel >> i & 1);
  };
  delay(5); // Delay to read
  return (analogRead(COM) >= 800.0f) == true ? HIGH : LOW;
}

#else

float readMux(unsigned char channel) {
  for (unsigned char i = 0; i < 3; i ++) {
    digitalWrite(controlPins[i], channel >> i & 1);
  };
  delay(8); // Delay to read
  return analogRead(COM);
};

int readDigitalMux(unsigned char channel) {
  for (unsigned char i = 0; i < 3; i ++) {
    digitalWrite(controlPins[i], channel >> i & 1);
  };
  delay(8); // Delay to read
  return (analogRead(COM) >= 800.0f) == true ? HIGH : LOW;
}

#endif

int led0 = 0,
  led1 = 0,
  led2 = 0,
  led3 = 0,
  led4 = 0;

long start_time = 0;

bool checkCont = true;

void checkButtons(bool ended_time) {
  if (ended_time || !led_0_active && !led0 || !led_1_active && !led1 || !led_2_active && !led2 || !led_3_active && !led3 || !led_4_active && !led4) {
    lcd.clear();
    long dt = (long) (start_time - millis() + (60000 * 10));
    int m = (dt / 60000);
    int s = (dt % 60000) / 1000;
    int ms = (dt % 1000) / 10;
    lcd.setCursor(4, 0);
    if (!ended_time) {
      if (m < 10) {
        lcd.print("0");
      };
      lcd.print(m, DEC);
      lcd.print(":");
      if (s < 10) {
        lcd.print("0");
      };
      lcd.print(s, DEC);
      lcd.print(":");
      if (ms < 10) {
        lcd.print("0");
      };
      lcd.print(ms, DEC);
    } else {
      lcd.print("00:00:00");
    };
    led_0_active = false;
    led_1_active = false;
    led_2_active = false;
    led_3_active = false;
    led_4_active = false;
    gameOn = false;
    selected = true;
    down = false;
    timetoturnoff = 0;
    led0 = 0;
    led1 = 0;
    led2 = 0;
    led3 = 0;
    led4 = 0;
    start_time = 0;
    buttonState = 0;
    updateLights();
    delay(1000);
    if (!ended_time) {
      while (dt > 0) {
        dt -= 8589;
        if (dt < 0) {
          dt = 0;
        };
        m = (dt / 60000);
        s = (dt % 60000) / 1000;
        ms = (dt % 1000) / 10;
        lcd.setCursor(4, 0);
        if (m < 10) {
          lcd.print("0");
        };
        lcd.print(m, DEC);
        lcd.print(":");
        if (s < 10) {
          lcd.print("0");
        };
        lcd.print(s, DEC);
        lcd.print(":");
        if (ms < 10) {
          lcd.print("0");
        };
        lcd.print(ms, DEC);
        delay(50);
      };
    };
    lcd.clear();
    lcd.setCursor(4, 0);
    lcd.print("00:00:00");
    delay(1500);
    lcd.clear();
    delay(1500);
    lcd.setCursor(4, 0);
    lcd.print("00:00:00");
    delay(500);
    lcd.clear();
    delay(400);
    lcd.setCursor(4, 0);
    lcd.print("00:00:00");
    delay(300);
    lcd.clear();
    delay(200);
    lcd.setCursor(4, 0);
    lcd.print("00:00:00");
    delay(200);
    lcd.clear();
    delay(200);
    lcd.setCursor(4, 0);
    lcd.print("00:00:00");
    for (int i = 0; i < 5; i++) {
      delay(150);
      lcd.clear();
      delay(150);
      lcd.setCursor(4, 0);
      lcd.print("00:00:00");
    };
    delay(100);
    lcd.clear();
    delay(2000);
    lcd.createChar(0, explode_0_0);
    lcd.createChar(1, explode_1_0);
    lcd.createChar(2, explode_2_0);
    lcd.createChar(3, explode_3_0);
    lcd.createChar(4, explode_4_0);
    lcd.createChar(5, explode_5_0);
    lcd.createChar(6, explode_6_0);
    lcd.createChar(7, explode_7_0);
    lcd.setCursor(6, 0);
    lcd.write(0);
    lcd.write(1);
    lcd.write(2);
    lcd.write(3);
    lcd.setCursor(6, 1);
    lcd.write(4);
    lcd.write(5);
    lcd.write(6);
    lcd.write(7);
    delay(100);
    lcd.createChar(0, explode_0_1);
    lcd.createChar(1, explode_1_1);
    lcd.createChar(2, explode_2_1);
    lcd.createChar(3, explode_3_1);
    lcd.createChar(4, explode_4_1);
    lcd.createChar(5, explode_5_1);
    lcd.createChar(6, explode_6_1);
    lcd.createChar(7, explode_7_1);
    delay(100);
    lcd.createChar(0, explode_0_2);
    lcd.createChar(1, explode_1_2);
    lcd.createChar(2, explode_2_2);
    lcd.createChar(3, explode_3_2);
    lcd.createChar(4, explode_4_2);
    lcd.createChar(5, explode_5_2);
    lcd.createChar(6, explode_6_2);
    lcd.createChar(7, explode_7_2);
    delay(250);
    lcd.setCursor(1, 0);
    lcd.print("GAME");
    delay(250);
    lcd.setCursor(11, 1);
    lcd.print("OVER");
    delay(2500);
    // Skull Emoji :skull:
    lcd.clear();
    lcd.createChar(0, skull_0);
    lcd.createChar(1, skull_1);
    lcd.createChar(2, skull_2);
    lcd.createChar(3, skull_3);
    lcd.createChar(4, skull_4);
    lcd.createChar(5, skull_5);
    lcd.createChar(6, skull_6);
    lcd.createChar(7, skull_7);
    lcd.setCursor(6, 0);
    lcd.write(0);
    lcd.write(1);
    lcd.write(2);
    lcd.write(3);
    lcd.setCursor(6, 1);
    lcd.write(4);
    lcd.write(5);
    lcd.write(6);
    lcd.write(7);
    delay(2500);
    lcd.clear();
    lcd.noBacklight();
    checkCont = false;
    start_time = 0;
  };
  if ((!led_0_active && led0 || led_0_active && !led0) && (!led_1_active && led1 || led_1_active && !led1) && (!led_2_active && led2 || led_2_active && !led2) && (!led_3_active && led3 || led_3_active && !led3) && (!led_4_active && led4 || led_4_active && !led4)) {
    lcd.clear();
    unsigned long dt = start_time - millis() + (60000 * 10);
    int m = (dt / 60000);
    int s = (dt % 60000) / 1000;
    int ms = (dt % 1000) / 10;
    lcd.setCursor(4, 0);
    if (m < 10) {
      lcd.print("0");
    };
    lcd.print(m, DEC);
    lcd.print(":");
    if (s < 10) {
      lcd.print("0");
    };
    lcd.print(s, DEC);
    lcd.print(":");
    if (ms < 10) {
      lcd.print("0");
    };
    lcd.print(ms, DEC);
    lcd.setCursor(4, 1);
    lcd.print("YOU WIN!");
    led_0_active = false;
    led_1_active = false;
    led_2_active = false;
    led_3_active = false;
    led_4_active = false;
    gameOn = false;
    selected = true;
    down = false;
    timetoturnoff = 0;
    led0 = 0;
    led1 = 0;
    led2 = 0;
    led3 = 0;
    led4 = 0;
    start_time = 0;
    buttonState = 0;
    updateLights();
    delay(5000);
    // Cutscene
    lcd.clear();
    delay(2500);
    lcd.clear();
    lcd.setCursor(4, 0);
    if (m < 10) {
      lcd.print("0");
    };
    lcd.print(m, DEC);
    lcd.print(":");
    if (s < 10) {
      lcd.print("0");
    };
    lcd.print(s, DEC);
    lcd.print(":");
    if (ms < 10) {
      lcd.print("0");
    };
    lcd.print(ms, DEC);
    lcd.setCursor(3, 1);
    lcd.print("IMPRESSIVE");
    delay(2500);
    lcd.clear();
    lcd.noBacklight();
    checkCont = false;
    start_time = 0;
  };
  return;
};

void randomizeInstructions(void) {
  led0 = random(10000000) % 2;
  led1 = random(20000000) % 2;
  led2 = random(30000000) % 2;
  led3 = random(40000000) % 2;
  led4 = random(50000000) % 2;
  while (led0 == led1 && led1 == led2 && led2 == led3 && led3 == led4) {
    led0 = random(10000000) % 2;
    led1 = random(20000000) % 2;
    led2 = random(30000000) % 2;
    led3 = random(40000000) % 2;
    led4 = random(50000000) % 2;
  };
  int binary = 0,
    mask = 1u;
  if (led0) {
    mask = 1u;
    mask = mask << 4;
    binary |= mask;
  };
  if (led1) {
    mask = 1u;
    mask = mask << 3;
    binary |= mask;
  };
  if (led2) {
    mask = 1u;
    mask = mask << 2;
    binary |= mask;
  };
  if (led3) {
    mask = 1u;
    mask = mask << 1;
    binary |= mask;
  };
  if (led4) {
    mask = 1u;
    mask = mask << 0;
    binary |= mask;
  };
  // I don't even know how I would implement a random generator into C++, I would only know how to do one in JS
  int num = random(100000) % 2;
  switch (binary) {
    case 0b00001:
      switch (num) {
        case 0:
          lcd.print("60349BH6LRLGV0");
          break;
        case 1:
          lcd.print("BF650DOOOEVS4G");
          break;
      };
      break;
    case 0b00010:
      switch (num) {
        case 0:
          lcd.print("JSL1YKKGX8ST3W");
          break;
        case 1:
          lcd.print("C19QSYILFWRQN1");
          break;
      };
      break;
    case 0b00011:
      switch (num) {
        case 0:
          lcd.print("TGDM73HFP6QHRW");
          break;
        case 1:
          lcd.print("E3204NQN05HCLR");
          break;
      };
      break;
    case 0b00100:
      switch (num) {
        case 0:
          lcd.print("CDIUWO9PS8KBXK");
          break;
        case 1:
          lcd.print("8T56IAYOG82O1B");
          break;
      };
      break;
    case 0b00101:
      switch (num) {
        case 0:
          lcd.print("777S96RAYQ71MR");
break;
        case 1:
          lcd.print("UIU2B9OJBGJRJG");
          break;
      };
      break;
    case 0b00110:
      switch (num) {
        case 0:
          lcd.print("12F3LYGYNHTNTB");
          break;
        case 1:
          lcd.print("Z6PK3680QFD3XG");
          break;
      };
      break;
    case 0b00111:
      switch (num) {
        case 0:
          lcd.print("URSFR9V55JKQB7");
          break;
        case 1:
          lcd.print("NRREVC2TSZRYF5");
          break;
      };
      break;
    case 0b01000:
      switch (num) {
        case 0:
          lcd.print("M1H4RMTEB2878A");
          break;
        case 1:
          lcd.print("JSEVKPDLTIKLNO");
          break;
      };
      break;
    case 0b01001:
      switch (num) {
        case 0:
          lcd.print("VFXJP5NKY3HL07");
          break;
        case 1:
          lcd.print("XG3FW7EAYYLNEU");
          break;
      };
      break;
    case 0b01010:
      switch (num) {
        case 0:
          lcd.print("H85BPINON3BVQ1");
          break;
        case 1:
          lcd.print("D45WMLPAE4V9ND");
          break;
      };
      break;
    case 0b01011:
      switch (num) {
        case 0:
          lcd.print("N5K39FLYLWEB5S");
          break;
        case 1:
          lcd.print("WSU14QC0P9VKDY");
          break;
      };
      break;
    case 0b01100:
      switch (num) {
        case 0:
          lcd.print("PJO1RKM7R92ZCL");
          break;
        case 1:
          lcd.print("TY89EZ4DV0DPBI");
          break;
      };
      break;
    case 0b01101:
      switch (num) {
        case 0:
          lcd.print("VPC5GPO26TNDLU");
          break;
        case 1:
          lcd.print("594JC0P8HTW6GM");
          break;
      };
      break;
    case 0b01110:
      switch (num) {
        case 0:
          lcd.print("PRB51J5CRDWTN3");
          break;
        case 1:
          lcd.print("DIZNZDTQAM1FB1");
          break;
      };
      break;
    case 0b01111:
      switch (num) {
        case 0:
          lcd.print("9ZQH1KI8BFYZTE");
          break;
        case 1:
          lcd.print("JN3ZESAUID2TI5");
          break;
      };
      break;
    case 0b10000:
      switch (num) {
        case 0:
          lcd.print("FBVAYHH50J88XW");
          break;
        case 1:
          lcd.print("J8FPO1A49Z3VS7");
          break;
      };
      break;
    case 0b10001:
      switch (num) {
        case 0:
          lcd.print("N8Q3S0DK3EG0W6");
          break;
        case 1:
          lcd.print("F5HZVZUQ4XT2SZ");
          break;
      };
      break;
    case 0b10010:switch (num) {
        case 0:
          lcd.print("SF1T68ZM77EFWW");
          break;
        case 1:
          lcd.print("VNXP94L3TKOOJ9");
          break;
      };
      break;
    case 0b10011:
      switch (num) {
        case 0:
          lcd.print("UJ7VQWKDY895GJ");
          break;
        case 1:
          lcd.print("BOXKU2TFKCH4CQ");
          break;
      };
      break;
    case 0b10100:
      switch (num) {
        case 0:
          lcd.print("ZWIBSSQZFPVZXP");
          break;
        case 1:
          lcd.print("R1Z7WW87QQSGJB");
          break;
      };
      break;
    case 0b10101:
      switch (num) {
        case 0:
          lcd.print("65MQVUSTT2WYOB");
          break;
        case 1:
          lcd.print("LNL066GKWMGJKT");
          break;
      };
      break;
    case 0b10110:
      switch (num) {
        case 0:
          lcd.print("9J3UYSGPT2IJJ2");
          break;
        case 1:
          lcd.print("B5826GNX3J6833");
          break;
      };
      break;
    case 0b10111:
      switch (num) {
        case 0:
          lcd.print("JCUUZLWBOPFY76");
          break;
        case 1:
          lcd.print("1Z0PR927P9YX59");
          break;
      };
      break;
    case 0b11000:
      switch (num) {
        case 0:
          lcd.print("7CSVDZHUEAD1D8");
          break;
        case 1:
          lcd.print("E2Z00QD1ZEE70H");
          break;
      };
      break;
    case 0b11001:
      switch (num) {
        case 0:
          lcd.print("4J61ELEZRDOH8U");
          break;
        case 1:
          lcd.print("801NEG66S62FMO");
          break;
      };
      break;
    case 0b11010:
      switch (num) {
        case 0:
          lcd.print("3NCZLQYDIBOHP9");
          break;
        case 1:
          lcd.print("MMU5ZD258V0PZ3");
          break;
      };
      break;
    case 0b11011:
      switch (num) {
        case 0:
          lcd.print("4VENTMY0BOVR3H");
          break;
        case 1:
          lcd.print("C3PW6UZ31A5W5E");
          break;
      };
      break;
    case 0b11100:
      switch (num) {
        case 0:
          lcd.print("NGT7Y2BL1IX74H");
          break;
        case 1:
          lcd.print("XLVJZ58BSKGTH2");
          break;
      };
      break;
    case 0b11101:
      switch (num) {
        case 0:
          lcd.print("D5U8XL4SM8Q7YP");
          break;
        case 1:
          lcd.print("LATZUYMDZHKBPE");
          break;
      };
      break;
    case 0b11110:
      switch (num) {
        case 0:
          lcd.print("PCAWKX81J49EBH");
break;
        case 1:
          lcd.print("JC3K0XELCLB7P9");
          break;
      };
      break;
  };
  return;
};

void loop(void) {
  buttonState = readDigitalMux(5);
  // Serial.println(buttonState);
  if (buttonState && timetoturnoff != -1 && !wait_1) {
    if (!down) {
      down = true;
      if (!gameOn) {
        gameOn = true;
        lcd.clear();
        lcd.backlight();
        // Init game
        lcd.setCursor(3, 0);
        lcd.print("B");
        delay(100);
        lcd.print("l");
        delay(100);
        lcd.print("o");
        delay(100);
        lcd.print("w");
        delay(100);
        lcd.print("n");
        delay(200);
        lcd.setCursor(11, 1);
        lcd.print("U");
        delay(100);
        lcd.print("p");
        delay(350);
        lcd.createChar(0, title_0);
        lcd.createChar(1, title_1);
        lcd.createChar(2, title_2);
        lcd.createChar(3, title_3);
        lcd.createChar(4, title_4);
        lcd.createChar(5, title_5);
        lcd.createChar(6, title_6);
        lcd.createChar(7, title_7);
        lcd.setCursor(14, 0);
        lcd.write(4);
        lcd.write(5);
        lcd.setCursor(14, 1);
        lcd.write(6);
        lcd.write(7);
        delay(100);
        lcd.setCursor(0, 0);
        lcd.write(0);
        lcd.write(1);
        lcd.setCursor(0, 1);
        lcd.write(2);
        lcd.write(3);
        delay(1000);
        lcd.clear();
        lcd.setCursor(4, 0);
        lcd.print("00:00:00");
        lcd.setCursor(0, 1);
        lcd.print("PRESS ANY BUTTON");
        start_time = 0;
        wait_1 = true;
      };
    };
    if (gameOn) {
        if (timetoturnoff == 0) {
          timetoturnoff = millis();
        } else {
          if (millis() - timetoturnoff > 2500) {
            gameOn = false;
            lcd.clear();
            lcd.noBacklight();
            timetoturnoff = -1;
            led_0_active = false;
            led_1_active = false;
            led_2_active = false;
            led_3_active = false;
            led_4_active = false;
            wait_1 = false;
            start_time = 0;
            led0 = 0;
            led1 = 0;
            led2 = 0;
            led3 = 0;
            led4 = 0;
            updateLights();
          };
        };
    };
  } else if (timetoturnoff != -1 && !wait_1) {
    down = false;
    timetoturnoff = 0;
  } else if (!buttonState && !wait_1) {
    timetoturnoff = 0;
  };
  if (gameOn) {
    buttonState_0 = readDigitalMux(0);
    buttonState_1 = readDigitalMux(1);
    buttonState_2 = readDigitalMux(2);
    buttonState_3 = readDigitalMux(3);
    buttonState_4 = readDigitalMux(4);
    buttonState_5 = readDigitalMux(5);
    if (wait_1) {
      if (buttonState_0 || buttonState_1 || buttonState_2 || buttonState_3 || buttonState_4 || buttonState_5) {
        if (buttonState_0) {
          while (buttonState_0) {
            delay(10);
            buttonState_0 = readDigitalMux(0);
          };
        };
        if (buttonState_1) {
          while (buttonState_0) {
            delay(10);
            buttonState_1 = readDigitalMux(1);
          };
        };
        if (buttonState_2) {
          while (buttonState_2) {
            delay(10);
            buttonState_2 = readDigitalMux(2);
          };
        };
        if (buttonState_3) {
          while (buttonState_3) {
            delay(10);
            buttonState_0 = readDigitalMux(3);
          };
        };
        if (buttonState_4) {
          while (buttonState_4) {
            delay(10);
            buttonState_4 = readDigitalMux(4);
          };
        };
        if (buttonState_5) {
          while (buttonState_5) {
            delay(10);
            buttonState_5 = readDigitalMux(5);
          };
        };
        lcd.clear();
        wait_1 = false;
        lcd.setCursor(4, 0);
        start_time = millis();
        lcd.print("10:00:00");
        lcd.setCursor(1, 1);
        randomizeInstructions();
        led_0_active = true;
        led_1_active = true;
        led_2_active = true;
        led_3_active = true;
        led_4_active = true;
      };
    } else {
      if (buttonState_0 && led_0_active) {
        led_0_active = false;
        checkButtons(false);
      } else if (buttonState_1 && led_1_active) {
        led_1_active = false;
        checkButtons(false);
      } else if (buttonState_2 && led_2_active) {
        led_2_active = false;
        checkButtons(false);
      } else if (buttonState_3 && led_3_active) {
        led_3_active = false;
        checkButtons(false);
      } else if (buttonState_4 && led_4_active) {
        led_4_active = false;
        checkButtons(false);
      };
      if (checkCont == false) {
        checkCont = true;
        return;
      };
      long dt = start_time - millis() + (60000 * 10);
      if (dt <= 0) {
        checkButtons(true);
        return;
      };
      int m = (dt / 60000);
      int s = (dt % 60000) / 1000;
      int ms = (dt % 1000) / 10;
      lcd.setCursor(4, 0);
      if (m < 10) {
        lcd.print("0");
      };
      lcd.print(m, DEC);
      lcd.print(":");
      if (s < 10) {
        lcd.print("0");
      };
      lcd.print(s, DEC);
      lcd.print(":");
      if (ms < 10) {
        lcd.print("0");
      };
      lcd.print(ms, DEC);
    }
    updateLights();
  };
#ifdef WOKWI
  delay(1);
#else
  delay(10);
#endif
};
74151APC ICBreakout
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module