#include <LiquidCrystal_I2C.h>
const int potPin = 34;

// variable for storing the potentiometer value
int potValue = 0;
const float GAMMA = 0.7;
const float RL10 = 50;

LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
  Serial.begin(115200);
  delay(1000);
  lcd.init();
  lcd.backlight();

}

void loop() {
  // Reading potentiometer value
  potValue = analogRead(potPin);

 float voltage = potValue / 4096. * 5;
  float resistance = 2000 * voltage / (1 - voltage / 5);
  float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
  

  Serial.println(lux);
  lcd.setCursor(0, 1);
  lcd.print("Lux: ");
  lcd.print(lux);

  
  lcd.setCursor(2, 0);
    lcd.print("Cahaya: ");
  if (lux > 50) {
    lcd.print("Terang");
   // digitalWrite(LDR_PIN, LOW);

  } else {
    lcd.print("Gelap  ");
    //digitalWrite(LDR_PIN, HIGH);


  

  }
  
  delay(500);
}