// LCD2004 Tiny Pacman on Wokwi
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
uint8_t pacman[8] = {
0b00000,
0b00000,
0b01110,
0b11011,
0b11111,
0b01110,
0b00000,
0b00000
};
uint8_t pacmanOpen[] = {
0b00000,
0b00000,
0b01110,
0b11011,
0b11100,
0b01110,
0b00000,
0b00000
};
uint8_t dot[] = {
0b00000,
0b00000,
0b00000,
0b00110,
0b00110,
0b00000,
0b00000,
0b00000
};
void setup() {
// Init
lcd.init();
lcd.backlight();
lcd.createChar(1, pacman);
lcd.createChar(2, dot);
lcd.begin(20, 4);
lcd.setCursor(0, 0);
lcd.print("Hermansyah Nur Ahmad");
lcd.setCursor(2, 1);
lcd.print("PAC-MAN_LCD2004");
lcd.setCursor(2, 2);
lcd.print("4 lines, 20 cols");
}
void loop() {
for (int i = 3; i < 16; i++) {
lcd.setCursor(i, 3);
lcd.print("\1");
for (int j = i + 1; j < 16; j++) {
lcd.setCursor(j, 3);
lcd.print("\2");
}
lcd.createChar(1, pacman);
delay(200);
lcd.createChar(1, pacmanOpen);
delay(200);
lcd.setCursor(i, 3);
lcd.print(" ");
}
delay(1000);
}