#define BLYNK_TEMPLATE_ID "TMPL69KWrcFVF"
#define BLYNK_TEMPLATE_NAME "ESP32"
#define BLYNK_AUTH_TOKEN "WK0BykPbSRzhMS8nZ4eLesIy7vtlgNuz"
#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <IRremote.h>
#include <LiquidCrystal_I2C.h>

int irPin = 19;
int lcd_SDA = 17;
int lcd_SCL = 16;
IRrecv receiver(irPin);
LiquidCrystal_I2C lcd(0x27, 20, 4);

void lcdPrint(char* text)
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("button pressed:");
  lcd.setCursor(0, 1);
  lcd.print(text);
  lcd.print(" code: ");
  lcd.print(receiver.decodedIRData.command);
}

void translateIR()
{
  
  switch (receiver.decodedIRData.command) {
    case 162:
      lcdPrint("POWER");
      break;
    case 226:
      lcdPrint("MENU");
      break;
    case 34:
      lcdPrint("TEST");
      break;
    case 2:
      lcdPrint("PLUS");
      break;
    case 194:
      lcdPrint("BACK");
      break;
    case 224:
      lcdPrint("PREV.");
      break;
    case 168:
      lcdPrint("PLAY");
      break;
    case 144:
      lcdPrint("NEXT");
      break;
    case 104:
      lcdPrint("num: 0");
      break;
    case 152:
      lcdPrint("MINUS");
      break;
    case 176:
      lcdPrint("key: C");
      break;
    case 48:
      lcdPrint("num: 1");
      break;
    case 24:
      lcdPrint("num: 2");
      break;
    case 122:
      lcdPrint("num: 3");
      break;
    case 16:
      lcdPrint("num: 4");
      break;
    case 56:
      lcdPrint("num: 5");
      break;
    case 90:
      lcdPrint("num: 6");
      break;
    case 66:
      lcdPrint("num: 7");
      break;
    case 74:
      lcdPrint("num: 8");
      break;
    case 82:
      lcdPrint("num: 9");
      break;
    default:
      lcd.clear();
      lcd.print(receiver.decodedIRData.command);
      lcd.print(" other button");
  }
}



void setup() {
  Wire.begin(lcd_SDA, lcd_SCL);
  lcd.init();
  lcd.backlight();
  lcd.print("Kyungsung");
  receiver.enableIRIn();
  //receiver.decodedIRData.command
  Blynk.begin(BLYNK_AUTH_TOKEN,"Wokwi-GUEST","","blynk.cloud",80);
}

void loop() {
    if (receiver.decode()) {
    translateIR();
    receiver.resume();  
  }
  Blynk.run();
}