#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Create an LCD object. Adjust the address (0x27) if necessary.
LiquidCrystal_I2C lcd(0x27, 16, 2); // 16 columns and 2 rows
// Button pin definitions (using pins 0-5)
const int button1Pin = 0;
const int button2Pin = 1;
const int button3Pin = 2;
const int button4Pin = 3;
const int button5Pin = 4;
const int button6Pin = 5;
void setup() {
// Initialize the LCD with the correct number of columns and rows
lcd.begin(16, 2);
lcd.backlight();
// Set button pins as input with internal pull-up resistors
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
pinMode(button4Pin, INPUT_PULLUP);
pinMode(button5Pin, INPUT_PULLUP);
pinMode(button6Pin, INPUT_PULLUP);
// Display initial message
lcd.setCursor(0, 0);
lcd.print("Press a Button");
}
void loop() {
// Check each button and display the corresponding alphabet on the LCD
if (digitalRead(button1Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("A");
delay(300); // Wait to prevent rapid blinking
} else if (digitalRead(button2Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("B");
delay(300);
} else if (digitalRead(button3Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("C");
delay(300);
} else if (digitalRead(button4Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("D");
delay(300);
} else if (digitalRead(button5Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("E");
delay(300);
} else if (digitalRead(button6Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("F");
delay(300);
}
}