#include <LiquidCrystal.h>
LiquidCrystal lcd(21, 19, 18, 5, 4, 2);
const int potentiometerPin = A0; // Analog input pin for the potentiometer
void setup()
{
lcd.begin(16, 2);
lcd.print("Akshat Yadav");
}
void loop()
{
lcd.clear(); // Clear the entire screen
lcd.setCursor(0, 0);
lcd.print("Akshat Yadav");
lcd.setCursor(0, 1);
lcd.print("Cont: ");
// Read the value from the potentiometer
int potValue = analogRead(potentiometerPin);
// Map the potentiometer value to a contrast range (0-255)
int contrast = map(potValue, 0, 1023, 0, 255);
// Set the LCD contrast
lcd.command(0x21); // LCD extended command mode
lcd.command(0x80 | contrast); // Set contrast (0-127)
lcd.command(0x20); // LCD basic command mode
lcd.print(contrast);
delay(1000); // Delay to prevent rapid LCD updates
}
// Send a command to the LCD
void LiquidCrystal::command(uint8_t value) {
send(value, LOW);
}