#define motionPin 18
#define ldrPin 21

int pirState = LOW;
int pirValue = 0;
const float GAMMA = 0.7;
const float RL10 = 50;


void cekKondisiCahaya(){
  int LDR_VALUE = analogRead(ldrPin);
  float voltage = analogValue / 1024. * 5;
  float resistance = 2000 * voltage / (1 - voltage / 5);
  float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1/GAMMA));

  lcd.setCursor(8,0);
  if(lux > 50){
    lcd.print("Terang !");
    digitalWrite(led, LOW);
    lcd.setCursor(9,3);
    lcd.print("           ");
  }else{
    lcd.print("Gelap !");
    digitalWrite(led, HIGH);
    cekGerakan();
  }
  lcd.setCursor(8,1);
  lcd.print(lux);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");
  pinMode(ldrPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(10); // this speeds up the simulation
}