#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // Alamat I2C dan ukuran LCD

int tombol1 = A0; 
int tombol2 = A2;    
int potensio = A1; 
int menu;
bool lepas;        
          

void setup() {
  lcd.begin(16, 2); 
  lcd.backlight();  
  lcd.print(" DLMS by chabib");
  pinMode(tombol1, INPUT); 
  pinMode(tombol2, INPUT);   
    lcd.setCursor(0,0); lcd.print("    DLMS 4.8    ");
    lcd.setCursor(0,1); lcd.print("preset by chabib");   
    delay(4000);
    lcd.clear();
}

void loop() {
  // buttonState = digitalRead(buttonPin); 
  int potValue = analogRead(potensio); // Membaca nilai potensiometer
  float mapping = potValue * (100.0/ 1023.0); // Menghitung tegangan berdasarkan nilai analog
  if(digitalRead(tombol1)==1 && lepas==0){
    lepas=1;
  }
    if(digitalRead(tombol1)==0 && lepas==1){
    menu=menu+1;
    if(menu>3)menu=0;
    lepas=0;
  }
  if(mapping>1){
    lcd.setCursor(0,0); lcd.print(">GAIN    MATRIK ");
    lcd.setCursor(0,1); lcd.print(" XOVER   EQ/MENU");
  }
    if(mapping>50){
    lcd.setCursor(0,0); lcd.print(" GAIN    MATRIK ");
    lcd.setCursor(0,1); lcd.print(">XOVER   EQ/MENU");
  }
    if(mapping>75){
    lcd.setCursor(0,0); lcd.print(" GAIN   >MATRIK ");
    lcd.setCursor(0,1); lcd.print(" XOVER   EQ/MENU");
  }
    if(mapping>80){
    lcd.setCursor(0,0); lcd.print(" GAIN    MATRIK ");
    lcd.setCursor(0,1); lcd.print(" XOVER  >EQ/MENU");
  }
  if(digitalRead(tombol2)==1 && menu==0){
  lcd.clear();

  lcd.setCursor(0,0); lcd.print(">GAIN");
  lcd.setCursor(0,1); lcd.print(mapping);
  }
}