#include <LiquidCrystal_I2C.h>
#define LED 2

//Karakteristrik LDR
const float GAMMA = 0.7;
const float RL10 = 50;
LiquidCrystal_I2C lcd(0x27, 20,4);

void setup() {
  pinMode(LED, OUTPUT);

  lcd.init();
  lcd.backlight();
}

void loop() {
  int analogValue = analogRead(A0);
  float tegangan = analogValue / 1024. * 5;
  float resistansi = 2000 * tegangan / (1 - tegangan / 5);
  float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistansi, (1/GAMMA));

  lcd.setCursor(2, 0);
  lcd.print("Cahaya:");
  if(lux > 50){
    lcd.print("Terang!");
    digitalWrite(LED,LOW);
  }else {
    lcd.print("Gelap!");
    digitalWrite(LED,HIGH);
  }
}