#ifndef CHAR_LCD_HPP #define CHAR_LCD_HPP #include "i2c_lcd_pcf8574.h" #define CHAR_LCD_I2C_NUM I2C_NUM_0 #define LCD_ADDR 0x27 #define LCD_COLS 20 #define LCD_ROWS 4 i2c_lcd_pcf8574_handle_t lcd; static const char *CHAR_LCD_TAG = "char_lcd"; void init_char_lcd(void) { lcd_init(&lcd, LCD_ADDR, CHAR_LCD_I2C_NUM); lcd_begin(&lcd, LCD_COLS, LCD_ROWS); // Turn on the backlight lcd_set_backlight(&lcd, 255); ESP_LOGI(CHAR_LCD_TAG, "LCD initialized"); } void example_lcd(void) { // Print a message lcd_set_cursor(&lcd, 0, 0); lcd_print(&lcd, "Hello, ESP32!"); lcd_set_cursor(&lcd, 0, 1); lcd_print(&lcd, "LCD Test"); int counter = 0; while (1) { vTaskDelay(20 / portTICK_PERIOD_MS); // Wait for 1 second // Update the counter on the LCD lcd_set_cursor(&lcd, 10, 1); char buffer[14]; snprintf(buffer, sizeof(buffer), "%5d", counter); lcd_print(&lcd, buffer); counter++; // Reset counter to avoid display overflow if (counter > 99999) counter = 0; } } #endif /* CHAR_LCD_HPP */