int ledPin=13;
#include <LiquidCrystal_I2C.h>
#define LED 13

const float GAMMA=0.7;
const float RL10=50;

LiquidCrystal_I2C lcd(0x27,16,2); //alamat dari LCD I2C

void setup() {
  // put your setup code here, to run once:
pinMode(LED, OUTPUT);
lcd.init();
lcd.backlight();
}

void loop() {
int analogValue=analogRead(A0);
//-----data analog 0 sampai 5v-----//
float voltage=analogValue/1024.*5;
float resistance=2000*voltage/(1-voltage/5);
float lux=pow(RL10*1e3*pow(10,GAMMA)/resistance,(1/GAMMA));
//-----perhitungan konveersi ke lux meter-----///

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