#include <LiquidCrystal.h>

// Use switch case instead of if:

// Blue = 6
// Red = 5
// Green = 4
// Yellow = 3

/*LiquidCrystal lcd (12, 11, 10, 9, 8, 7);
int stev = 0;
int del = 50;


void setup() {
  randomSeed(analogRead(A0));
  Serial.begin(115200);
  DDRD &= 0x87;
  PORTD |= 0xFF;
  lcd.begin(16, 2);
}

void loop() {
  bool blu = PIND & (1 << PD6); 
  if (blu == 0) {
    stev ++;
    lcd.setCursor(0, 0);
    lcd.print(stev);
    delay(del*3);
  }
  bool red = PIND & (1 << PD5);
  if (red == 0) {
    lcd.setCursor(0, 0);
    lcd.print(stev);
    stev --;
    delay(del*3);
  }
  bool green = PIND & (1 << PD4);
  if (green == 0) {
    lcd.setCursor(0, 0);
    lcd.print(stev);
    stev = 0;
  }
  bool yellow = PIND & (1 << PD3); 
  if (yellow == 0) {
    lcd.setCursor(0, 0);
    lcd.print(stev);
    stev = random(1, 10);
    delay(del*2);
  }
  lcd.setCursor(0, 0);
  lcd.clear();
  lcd.print(stev);
  delay(del);
}*/


LiquidCrystal lcd (12, 11, 10, 9, 8, 7);
int stev = 0;
int del = 50;
int m;
byte srce [8] = {
  0b00000,
  0b01010,
  0b11111,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000
};

void setup() {
  randomSeed(analogRead(A0));
  Serial.begin(115200);
  DDRD &= 0x83;
  PORTD |= 0xFF;
  lcd.createChar(1, srce);
  lcd.begin(16, 2);
}

void loop() {
  bool blu = PIND & (1 << PD6); 
  bool red = PIND & (1 << PD5);
  bool green = PIND & (1 << PD4);
  bool yellow = PIND & (1 << PD3); 
  bool grey = PIND & (1 << PD2);
  if (blu == 0){
    m = 1;
  }
  if (red == 0) {
    m = 2;
  }
  if (green == 0) {
    m = 3;
  }
  if (yellow == 0) {
    m = 4;
  }
  if (grey == 0) {
    m = 5;
  }
  switch (m) {
    case 1:
      {
        stev ++;
        lcd.setCursor(0, 1);
        lcd.print(stev);
        delay(del*3);
        m = 0;
        break;
      };
    case 2:
      {
        lcd.setCursor(0, 0);
        lcd.print(stev);
        stev --;
        delay(del*3);
        m = 0;
        break;
      };
    case 3:
      {
        lcd.setCursor(0, 0);
        lcd.print(stev);
        stev = 0;
        m = 0;
        break;
      };
    case 4:
      {
        lcd.setCursor(0, 0);
        lcd.print(stev);
        stev = random(1, 10);
        delay(del*2);
        m = 0;
        break;
      };
    case 5:
      {
        lcd.setCursor(0, 0);
        lcd.clear();
        lcd.write(1);
        delay(del*2);
        m = 5;
        break;
      }
    default: 
      {
        m = 0;
        break;
      }
  }
  
  lcd.setCursor(0, 0);
  lcd.clear();
  if (m != 5) {
    lcd.print(stev);
  }
  else {
    lcd.write(1);
  }
  delay(del);
}