#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the library with the I2C address (0x27 or 0x3F)
LiquidCrystal_I2C lcd(0x27, 16, 2);
int x = 0; // Starting position of the horse
// Two frames of the horse (head up and head down)
byte horseFrames[2][8][8] = {
{
{0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0E}, // Head Up
{0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x1F, 0x1F},
{0x00, 0x00, 0x00, 0x03, 0x07, 0x1F, 0x1F, 0x1F},
{0x00, 0x00, 0x05, 0x1F, 0x1D, 0x1F, 0x16, 0x06},
{0x0C, 0x18, 0x10, 0x00, 0x01, 0x01, 0x01, 0x00},
{0x1F, 0x1F, 0x1E, 0x17, 0x00, 0x00, 0x10, 0x00},
{0x1F, 0x1F, 0x03, 0x02, 0x14, 0x04, 0x02, 0x00},
{0x1C, 0x1C, 0x04, 0x04, 0x08, 0x00, 0x00, 0x00}
},
{
{0x00, 0x00, 0x00, 0x07, 0x0F, 0x0E, 0x1C, 0x18}, // Head Down
{0x00, 0x00, 0x00, 0x0F, 0x1F, 0x1F, 0x1F, 0x1F},
{0x00, 0x00, 0x01, 0x03, 0x1F, 0x1F, 0x1F, 0x1F},
{0x14, 0x1C, 0x1A, 0x1E, 0x1F, 0x13, 0x10, 0x10},
{0x13, 0x13, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00},
{0x1F, 0x07, 0x0E, 0x06, 0x01, 0x00, 0x00, 0x00},
{0x0F, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00},
{0x10, 0x18, 0x0C, 0x02, 0x02, 0x11, 0x00, 0x00}
}
};
void setup() {
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
// Alternate between frames and move the horse from left to right
for (x = 0; x <= 12; x++) { // Move from position 0 to 12
for (int f = 0; f < 2; f++) { // Alternate between frame 0 and frame 1 (head up, head down)
lcd.clear();
// Load the current frame (f) into LCD memory
for (int i = 0; i < 8; i++) {
lcd.createChar(i, horseFrames[f][i]);
}
// Display the horse on the LCD moving from left to right
for (int c = 0; c < 4; c++) { // 4 character-wide horse
lcd.setCursor(x + c, 0); // Top half of the horse
lcd.write(byte(c)); // Display top part
lcd.setCursor(x + c, 1); // Bottom half of the horse
lcd.write(byte(c + 4)); // Display bottom part
}
delay(40); // Adjust delay to control the animation speed
}
}
// Clear the LCD after the animation runs
lcd.clear();
}
void loop() {
// Do nothing, as the animation runs only once in the setup
}