#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with I2C address (check your device's address)
LiquidCrystal_I2C lcd(0x27, 16, 2); // 0x27 is a common address for I2C LCDs
// Custom characters (5x8 grid)
byte heart[8] = {
B00000,
B01010,
B11111,
B11111,
B01110,
B00100,
B00000,
B00000
};
byte diamond[8] = {
B00100,
B01110,
B11111,
B11111,
B11111,
B01110,
B00100,
B00000
};
byte box[8] = { // Renamed from square to box
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
byte triangle[8] = {
B00000,
B00100,
B01110,
B11111,
B11111,
B11111,
B11111,
B11111
};
void setup() {
lcd.begin(16, 2); // Initialize the 16x2 LCD
lcd.backlight(); // Turn on the backlight
// Load custom characters into locations 0-3
lcd.createChar(0, heart);
lcd.createChar(1, diamond);
lcd.createChar(2, box); // Use box instead of square
lcd.createChar(3, triangle);
// Initial display
lcd.setCursor(0, 0);
lcd.write(byte(0)); // Display heart
lcd.setCursor(1, 0);
lcd.write(byte(1)); // Display diamond
lcd.setCursor(2, 0);
lcd.write(byte(2)); // Display box
lcd.setCursor(3, 0);
lcd.write(byte(3)); // Display triangle
}
void loop() {
// Rotate shapes across the LCD screen
for (int i = 0; i < 4; i++) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.write(byte(i % 4)); // Display shape in position 0
lcd.setCursor(1, 0);
lcd.write(byte((i + 1) % 4)); // Display shape in position 1
lcd.setCursor(2, 0);
lcd.write(byte((i + 2) % 4)); // Display shape in position 2
lcd.setCursor(3, 0);
lcd.write(byte((i + 3) % 4)); // Display shape in position 3
delay(500); // Delay for rotation effect
}
}