#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
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
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
if (digitalRead(button1Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Button 1 Pressed");
} else if (digitalRead(button2Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Button 2 Pressed");
} else if (digitalRead(button3Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Button 3 Pressed");
} else if (digitalRead(button4Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Button 4 Pressed");
} else if (digitalRead(button5Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Button 5 Pressed");
} else if (digitalRead(button6Pin) == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Button 6 Pressed");
}
}