#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int potPin = 35;
int potValue = 0;
void setup() {
Serial.begin(115200);
// Initialize the I2C LCD
lcd.init();
lcd.backlight();
// Display initial message
lcd.setCursor(0, 0);
lcd.print("Potentiometer");
lcd.setCursor(0, 1);
lcd.print("Test with ESP32");
delay(2000);
lcd.clear();
}
void loop() {
potValue = analogRead(potPin);
// Clear the previous content on the LCD
// lcd.clear();
// Display the potentiometer value
lcd.setCursor(0, 0);
lcd.print("Pot Value: ");
lcd.print(potValue);
// Map the raw value to a percentage (0 to 100%)
int percentage = map(potValue, 0, 4095, 0, 100);
lcd.setCursor(0, 1);
lcd.print("Percentage: ");
lcd.print(percentage);
lcd.print(" %");
// Print to Serial Monitor for debugging
Serial.print("Potentiometer Value: ");
Serial.print(potValue);
Serial.print(" | Percentage: ");
Serial.println(percentage);
delay(500);
}