#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Initialize the LCD with address 0x27, 16 columns, and 2 rows
int buttonPin = 3; // Pin for the button
int ledPin = 2; // Pin for the LED
int buttonState = 0;
void setup() {
pinMode(buttonPin, INPUT); // Configure buttonPin as input
pinMode(ledPin, OUTPUT); // Configure ledPin as output
lcd.begin(16, 2); // Set the LCD's number of columns and rows
lcd.backlight(); // Turn on the LCD backlight
lcd.setCursor(0, 0); // Set cursor to the first row
lcd.print("INTERFACING LCD"); // Print a message to the LCD
lcd.setCursor(0, 1); // Set cursor to the second row
lcd.print("WITH ARDUINO"); // Print a message to the LCD
delay(10000
); // Wait for 1 second
lcd.clear(); // Clear the LCD
}
void loop() {
buttonState = digitalRead(buttonPin); // Read the button state
if (buttonState == LOW) { // If button is not pressed
lcd.setCursor(0, 0); // Set cursor to the first row
lcd.print("BUTTON NOT PRESS"); // Print a message
lcd.setCursor(0, 1); // Move cursor to the second row
lcd.print(" "); // Clear the second row
digitalWrite(ledPin, LOW); // Turn off the LED
delay(100);
} else { // If button is pressed
lcd.setCursor(0, 0); // Set cursor to the first row
lcd.print("BUTTON PRESS "); // Print a message
lcd.setCursor(0, 1); // Move cursor to the second row
lcd.print("LED ON "); // Print a message indicating LED is on
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(100);
}
}