#include <LiquidCrystal_I2C.h>
#define led3 3
#define led4 4
#define led3on 777111
#define led4on 777333
#define led4off 777330
#define led4utripa 777444
static bool i=false;
LiquidCrystal_I2C lcd(0x27,16,2);



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Vnesite kodo");
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Vpisi kodo");
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()){
    char vpis[7];
    int steviloZnakovVpis=Serial.readBytes(vpis,6);
    if(steviloZnakovVpis==6){
      vpis[6]='\0';
      int stevilka=atoi(vpis);
      switch(stevilka){
        case led3on:
          Serial.println("LED3 VKLOP");
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("LED 3 VKLOP");
          digitalWrite(led3, HIGH);
          break;
        case led4on:
          Serial.println("LED4 UTRIPANJE");
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("LED 4 UTRIPANJE");
          digitalWrite(led4, HIGH);
          i=true;
          break;
        case led4off:
        Serial.println("LED4 IZKLOP");
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("LED 4 IZKLOP");
          digitalWrite(led4, LOW);
          i=false;
          break;
        case led4utripa:
          Serial.println("utrip 10x");
          utrip();
          break;
        default:
          Serial.println("Poskusi znova");
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("Poskusi");
          lcd.setCursor(0,1);
          lcd.print("Znova");
          while(Serial.available())Serial.read();
          break;
      }
    }
  }
  static unsigned long trenutniCas;
  int zakasnitev=200;
  static bool m=false;
  if((millis()-trenutniCas)>zakasnitev && i){
    trenutniCas=millis();
    m=!m;
    digitalWrite(led4,m);
  }
}
void utrip(){
  digitalWrite(led4, HIGH);
  delay(300);
  digitalWrite(led4, LOW);
  delay(300);
}