#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with I2C address 0x27 and dimensions 16x2
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Set up LED pin
const int ledPin = 16; // GPIO16 for ESP32
int blinkCount = 0; // Variable to store blink count
void setup() {
// Initialize I2C with custom SDA and SCL pins
Wire.begin(21, 19); // SDA on GPIO 21, SCL on GPIO 19
// Initialize LCD with columns and rows
lcd.begin(16, 2);
lcd.backlight(); // Turn on LCD backlight
pinMode(ledPin, OUTPUT);
// Display initial message
lcd.setCursor(0, 0);
lcd.print("LED Blink Count:");
lcd.setCursor(0, 1);
lcd.print(blinkCount);
}
void loop() {
// Turn LED on
digitalWrite(ledPin, HIGH);
delay(500); // Wait for 0.5 second
// Turn LED off
digitalWrite(ledPin, LOW);
delay(500); // Wait for 0.5 second
// Update blink count and display on LCD
blinkCount++;
lcd.setCursor(0, 1);
lcd.print(" "); // Clear previous count
lcd.setCursor(0, 1);
lcd.print(blinkCount);
}