#include <Servo.h>
#include <LiquidCrystal_I2C.h>

#define BLYNK_TEMPLATE_ID "TMPLwSyhvUZD"
#define BLYNK_DEVICE_NAME "Dual Servo"
#define BLYNK_AUTH_TOKEN "QGA0i3D_oLJmWyG6W5YMDgvopn1DgCvf"
  
#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "Wokwi-GUEST";
char pass[] = "";

int ldr, hujan;
Servo motor_1;
Servo motor_2;

bool status = false;
BLYNK_WRITE(V0)
{
  int pinValue = param.asInt();
  
  if (pinValue ==1){
    status = true;
  }
  else{
    status = false;
  }
}

LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
  lcd.init();
  Serial.begin(115200);
  motor_1.attach(25);
  motor_2.attach(26);
  Blynk.begin(auth, ssid, pass);

}

void loop() {
  Blynk.run();
  ldr =map(analogRead(34),0,4096,100,0);
  hujan =map(analogRead(35),0,4096,0,100);

  if(status == true){
  motor_1.write(0);
  motor_2.write(0);
  Serial.println("motor Hidup");
 
  }else{
    if(ldr <20 || hujan >45){
      motor_1.write(180);
      motor_2.write(180);
      Serial.println("motor mati");
    }
  }
  lcd.print("    DTM PROJECT");
    lcd.setCursor(0,0);
  lcd.backlight();
  delay(50);
  lcd.noBacklight();
  delay(50);

}