#include <LiquidCrystal_I2C.h>

//integrasi led
const int col = 16;
const int row = 2;
LiquidCrystal_I2C lcd(0x27, col, row);
int posisi = 0;

//pin joystik
const int ver_pin = 27;
const int hor_pin = 26;
const int sel_pin = 25;

void setup() {
  Serial.begin(9600);
  //validasi lcd
  lcd.init();
  lcd.backlight();

  //validasi pin joystik
  pinMode(ver_pin, INPUT);
  pinMode(hor_pin, INPUT);
  pinMode(sel_pin, INPUT_PULLUP);
}

void tampilkanPesan(String pesan) {
    lcd.setCursor(posisi, 0);
    lcd.print(pesan);
    delay(1000);
    lcd.clear();
}

void loop() {
  //pengecekan validasi
  int hor = analogRead(hor_pin);
  int ver = analogRead(ver_pin);
  int sel = analogRead(sel_pin);


  if (ver == 4095 && hor == 2048) {
    tampilkanPesan("atas");
  }
  if (ver == 0 && hor == 2048) {
    tampilkanPesan("bawah");
  }
  if (ver == 2048 && hor == 4095 ) {
    tampilkanPesan("kiri");
  }
  if (ver == 2048 && hor == 0) {
    tampilkanPesan("kanan");
  }
  if (sel == LOW) {
    tampilkanPesan("tengah");
  }
}