#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the I2C address and LCD dimensions
// Custom character for the walking character
byte walkingCharacter[8] = {
B00100,
B01110,
B00100,
B01110,
B10101,
B00100,
B01010,
B10001
};
void setup() {
lcd.begin(16, 2); // Initialize the LCD
lcd.createChar(0, walkingCharacter); // Create custom character for the walking character
lcd.backlight(); // Turn on the backlight
}
void loop() {
walkLeftToRight(); // Move the character from left to right
walkRightToLeft(); // Move the character from right to left
}
void walkLeftToRight() {
for (int i = 0; i < 16; ++i) {
lcd.clear(); // Clear the LCD
lcd.setCursor(i, 0); // Set cursor to the current position
lcd.write(byte(0)); // Display the walking character
delay(200); // Adjust the delay for animation speed
}
}
void walkRightToLeft() {
for (int i = 15; i >= 0; --i) {
lcd.clear(); // Clear the LCD
lcd.setCursor(i, 0); // Set cursor to the current position
lcd.write(byte(0)); // Display the walking character
delay(200); // Adjust the delay for animation speed
}
}