#include <LiquidCrystal_I2C.h> //ของ wokwi
#define I2C_ADDR 0x27 //ของ wokwi
#define LCD_COLUMNS 20 //ของ wokwi
#define LCD_LINES 4 //ของ wokwi
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES); //ของ wokwi
void setup()
{
lcd.begin(20, 4);
Serial.begin(9600); // Serial Port initialization
lcd.clear();
}
char a_byte = 0;// defining a character data for a variable
String a_str = "";// creating a string having space
void loop() {
if (Serial.available() > 0) { /*checking if any input is given on the Serial monitor*/
a_byte = Serial.read(); /*read if there is any input and save it in the character data type variable*/
if (a_byte != '\n') {/*to display the data on the next line one line space is added to the string */
a_str += a_byte;
}
else {
Serial.println(a_str); // print the string on the serial monitor
lcd.clear();
lcd.setCursor(0,0);// setting the place for the data
lcd.print(a_str);// print the data on the LCD
a_str = "";
Serial.println("");// printing the string having space
}
}
}