#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define POTENTIOMETER_PIN 34 // Analog input pin for potentiometer
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change address to 0x3F if 0x27 doesn't work
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Bar Graph:");
}
void loop() {
// Read potentiometer value (0-4095 for 12-bit ADC)
int sensorValue = analogRead(POTENTIOMETER_PIN);
// Map the sensor value to a range for the bar graph (0-16 characters)
int barLength = map(sensorValue, 0, 4095, 0, 16);
// Clear previous display
lcd.setCursor(0, 1);
lcd.print(" "); // Clear the second row
// Draw the bar graph
lcd.setCursor(0, 1);
for (int i = 0; i < barLength; i++) {
lcd.print((char)255); // Use character 255 for filled blocks
}
delay(500); // Update every 500 ms
}