#define BLYNK_TEMPLATE_ID "TMPL6tvxo7Vsk"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN    "WLycV07YqWdAloxm4Je4ze9alyHZqudS"
#define BLYNK_PRINT Serial

#include <LiquidCrystal_I2C.h>
#include <DHTesp.h>
#include <WiFi.h>
#include "RTClib.h"
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

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

BlynkTimer timer;

LiquidCrystal_I2C lcd(0x27, 20, 4);
const int DHT_PIN = 15;
#define ldrpin 32
const float GAMMA = 0.7;
const float RL10 = 50;
int volumeAir, siram;

DHTesp dhtSensor;
RTC_DS1307 rtc;

const int DIR = 19;
const int STEP = 18;
const int REV = 200;
const int DER = 2;
const int STIP = 34;
const int RIR = 25;
const int LIR = 26;

void bacaSensor() {
  // Existing code from Kode Program 1
}

BLYNK_WRITE(V9) {
  volumeAir = param.asInt();
}

BLYNK_WRITE(V0) {
  siram = param.asInt();
}

void setup() {
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");

  lcd.init();
  lcd.backlight();
  lcd.println("Kelompok 7");

  dhtSensor.setup(DHT_PIN, DHTesp::DHT22);

  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

  pinMode(STEP, OUTPUT);
  pinMode(DIR, OUTPUT);
  pinMode(STIP, OUTPUT);
  pinMode(DER, OUTPUT);
  pinMode(RIR, INPUT);
  pinMode(LIR, INPUT);

  timer.setInterval(1000L, bacaSensor);
}

void loop() {
  Blynk.run();
  timer.run();

  Serial.println("Area Scanning");

  if ((digitalRead(RIR) == 1) && (digitalRead(LIR) == 1)) {
    forward();
  }
  if ((digitalRead(RIR) == 0) && (digitalRead(LIR) == 1)) {
    turnRight();
  }
  if ((digitalRead(RIR) == 1) && (digitalRead(LIR) == 0)) {
    turnLeft();
  }
  if ((digitalRead(RIR) == 0) && (digitalRead(LIR) == 0)) {
    stop();
  }
}

void forward() {
  // Existing code from Kode Program 2
  Serial.println("Vehicle initiated to go forward");
}

void turnRight() {
  // Existing code from Kode Program 2
  delay(5000);
  Serial.println("Vehicle initiated to turn right");
}

void turnLeft() {
  // Existing code from Kode Program 2
  delay(5000);
  Serial.println("Vehicle initiated to turn left");
}

void stop() {
  // Existing code from Kode Program 2
  Serial.println("Vehicle initiated to go backward");
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND
ldr1:VCC
ldr1:GND
ldr1:DO
ldr1:AO
lcd2:GND
lcd2:VCC
lcd2:SDA
lcd2:SCL
GND5VSDASCLSQWRTCDS1307+
rtc1:GND
rtc1:5V
rtc1:SDA
rtc1:SCL
rtc1:SQW
stepper2:A-
stepper2:A+
stepper2:B+
stepper2:B-
A4988
drv1:ENABLE
drv1:MS1
drv1:MS2
drv1:MS3
drv1:RESET
drv1:SLEEP
drv1:STEP
drv1:DIR
drv1:GND.1
drv1:VDD
drv1:1B
drv1:1A
drv1:2A
drv1:2B
drv1:GND.2
drv1:VMOT
A4988
drv2:ENABLE
drv2:MS1
drv2:MS2
drv2:MS3
drv2:RESET
drv2:SLEEP
drv2:STEP
drv2:DIR
drv2:GND.1
drv2:VDD
drv2:1B
drv2:1A
drv2:2A
drv2:2B
drv2:GND.2
drv2:VMOT
ir1:GND
ir1:VCC
ir1:DAT
ir2:GND
ir2:VCC
ir2:DAT
stepper1:A-
stepper1:A+
stepper1:B+
stepper1:B-