#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Pin potensiometer (hubungkan ke pin ADC ESP32, misalnya GPIO34)
const int potPin = 34;
int potValue = 0;
int x = 0; // counter
int state = 0; // status
int threshold = 2000; // batas deteksi (0–4095 ADC ESP32)
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200); // aktifkan serial monitor
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" Parkir Mobil ");
lcd.setCursor(0, 1);
lcd.print(x);
lcd.print(" Mobil Masuk ");
}
void loop() {
potValue = analogRead(potPin); // baca potensiometer
// tampilkan nilai ADC real-time
Serial.print("ADC Value: ");
Serial.print(potValue);
Serial.print(" | Mobil: ");
Serial.println(x);
if (state == 0) {
if (potValue > threshold) {
state = 1;
x++;
lcd.setCursor(0, 1);
lcd.print(" "); // clear baris 2
lcd.setCursor(0, 1);
lcd.print(x);
lcd.print(" Mobil Masuk ");
// tampilkan juga ketika counter bertambah
Serial.println(">>> Threshold tercapai, counter++");
}
}
if (potValue < threshold - 200) { // histeresis
state = 0;
}
delay(500); // beri jeda biar data di serial tidak terlalu cepat
}