#include <Wire.h>  // Include the Wire library for I2C communication
#include <LiquidCrystal_I2C.h>  // Include the LiquidCrystal_I2C library for LCD

#define printf _printf

LiquidCrystal_I2C lcd(0x27, 20, 4);  // Set the LCD address and dimensions

void setup() {
  Serial.begin(115200);
  lcd.init();  // Initialize the LCD
  lcd.backlight();  // Turn on the LCD backlight
  printf("Hello, printf()!\n");
  lcd.clear();  // Clear the LCD screen
}

void loop() {
  printf("Millis: %lu\n", millis());
  lcd.setCursor(0, 1);  // Set the LCD cursor to the second row
  lcd.print("Millis: ");
  lcd.print(millis());
  delay(1000);
  lcd.clear();  // Clear the LCD screen after displaying the data
}

int _printf(char *format, ...) {
  char buffer[80];
  va_list aptr;
  int ret;

  va_start(aptr, format);
  ret = vsprintf(buffer, format, aptr);
  va_end(aptr);
  Serial.print(String(buffer));
  return (ret);
}