#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // กำหนดที่อยู่ I2C ของ LCD (0x27 เป็นที่อยู่ที่พบบ่อย)
const int heartWidth = 8; // ความกว้างของหัวใจ
const int heartHeight = 5; // ความสูงของหัวใจ
// รูปหัวใจ
byte heartShape[heartWidth] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};
void setup() {
Serial.begin(115200);
lcd.init();
lcd.backlight();
// สร้างรูปหัวใจในตัวอักษร
lcd.createChar(0, heartShape);
// แสดงข้อความ
lcd.setCursor(0, 0);
lcd.print(" Visca barca.");
}
void loop() {
// แสดงหัวใจเคลื่อนไหว
for (int i = 0; i < 16; i++) {
lcd.setCursor(i, 1); // เคลื่อนที่ไปยังตำแหน่งในแถวที่ 2
lcd.write(0); // แสดงหัวใจ
delay(200);
lcd.setCursor(i, 1); // เคลื่อนที่กลับไปยังตำแหน่งเดิม
lcd.write(' '); // ลบหัวใจ
}
}