//https://docs.wokwi.com/parts/wokwi-lcd1602
//https://wokwi.com/projects/344891772964438612
//LiquidCrystal I2C Hello World program
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16 //20
#define LCD_LINES 4 // 2
#define col0 0
#define row0 0
#define row1 1
#define rightColumnPosition15 15 // ตำแหน่งขวามือสุดคือ ตำแหน่ง 15
#define lefColumnPosition0 0 // ตำแหน่งซ้ายมือสุดคือ ตำแหน่ง 0
#define dly100 100
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES); // lcd เป็นชื่อเล่น
char* msg ="Hello";
char* msgW ="World";
void setup() {
Serial.begin(115200);
// Init
lcd.init();
lcd.backlight();
}
//--- left to right
void leftTOright(char* H){
for (int x=lefColumnPosition0; x<=rightColumnPosition15; x++) { // left to right
lcd.setCursor(x, row0);
lcd.print(H);
delay(dly100);
lcd.clear();
}
}
//--- right to left
void rightTOleft(char* H) {
for (int x=rightColumnPosition15; x>=lefColumnPosition0; x--) { // right to left
lcd.setCursor(x, row0);
lcd.print(H);
delay(dly100);
lcd.clear();
}
}
//---
void loop() {
//lcd.setCursor(0, 0);
//lcd.print("Hello, world!");
leftTOright(msg);
rightTOleft(msgW);
}
// end program