<LiquidCrystal.h>
//กำหนดขนาดของจอ LCD (จำนวนคอลัมน์และแถว)
LiquidCrystal lcd(16, 2);
void setup() {
// กำหนดความสูงของตัวอักษรบนจอ LCD (ตามขนาดของจอที่คุณใช้)
lcd.begin(16, 2);
}
void loop() {
// ข้อความที่คุณต้องการแสดงบนจอ LCD
String message = "Hello, World!";
// วิ่งข้อความซ้ายไปขวา
for (int i = 0; i < message.length() + 16; i++) {
lcd.clear();
lcd.setCursor(i, 0);
// นำมาแสดงบนจอ LCD
for (int j = 0; j < 16; j++) {
int index = i + j;
if (index >= 0 && index < message.length()) {
lcd.write(message.charAt(index));
}
}
// หน่วงเวลาสั้น ๆ
delay(500);
}
}VSS (Pin 1): ต่อกับ GND
VDD (Pin 2): ต่อกับ 5V
VO (Pin 3): ต่อกับ ตัวแปร potentiometer (เพื่อปรับค่าความสว่าง)
RS (Pin 4): ต่อกับ ขา 7 ของ Arduino
RW (Pin 5): ต่อกับ GND
E (Pin 6): ต่อกับ ขา 6 ของ Arduino
D4 (Pin 11): ต่อกับ ขา 5 ของ Arduino
D5 (Pin 12): ต่อกับ ขา 4 ของ Arduino
D6 (Pin 13): ต่อกับ ขา 3 ของ Arduino
D7 (Pin 14): ต่อกับ ขา 2 ของ Arduino
A (Pin 15): ต่อกับ 5V
K (Pin 16): ต่อกับ GND
ใช้โค้ดต่อไปนี้สำหรับ Arduino:
cpp
Copy code
#include <LiquidCrystal.h>
// กำหนดขนาดของ LCD
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup() {
// กำหนดขนาดหน้าจอ LCD (จำนวนคอลัมน์และแถว)
lcd.begin(16, 2);
// แสดงข้อความเริ่มต้น
lcd.print("Hello, World!");
delay(1000);
}
void loop() {
// นำข้อความไปทางซ้าย
lcd.scrollDisplayLeft();
delay(300);
// หากค่าคอลัมน์ที่ 0 น้อยกว่า -16 (ข้อความออกนอกหน้าจอ)
if (lcd.getCursorCol() < -15) {
// สั่งให้ข้อความเริ่มต้นแสดงใหม่
lcd.setCursor(16, 1);
}
}