#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Initialize the LCD
lcd.init();
// Turn on the backlight
lcd.backlight();
// Set up custom characters for the bed and person
setupCustomCharacters();
}
void loop() {
// Display initial state: person sleeping in bed
displayPersonInBed();
// Wait for a few seconds to simulate sleeping
delay(5000);
// Display waking up and getting out of bed animation
displayWakingUpAndGettingOut();
// Wait for a few seconds before repeating the loop
delay(5000);
}
// Function to set up custom characters for the bed and person
void setupCustomCharacters() {
// Define custom characters for the bed
byte bedCharacter[8] = {
B00000,
B00000,
B00000,
B00000,
B11111,
B11111,
B11111,
B11111
};
// Define custom characters for the person
byte personCharacter[8] = {
B01110,
B11111,
B01010,
B01110,
B01110,
B01010,
B11111,
B00000
};
// Create custom characters for the bed and person
lcd.createChar(0, bedCharacter);
lcd.createChar(1, personCharacter);
}
// Function to display the person in bed
void displayPersonInBed() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.write(byte(0)); // Display bed character
lcd.setCursor(6, 0);
lcd.write(byte(1)); // Display person in bed character
lcd.setCursor(1, 1);
lcd.print("Zzzz...");
}
// Function to display waking up and getting out of bed animation
void displayWakingUpAndGettingOut() {
for (int i = 0; i < 5; i++) {
// Display waking up animation
lcd.clear();
lcd.setCursor(0, 0);
lcd.write(byte(0)); // Display bed character
lcd.setCursor(6, 0);
lcd.write(byte(1)); // Display waking up person character
lcd.setCursor(1, 1);
lcd.print("Waking up...");
delay(1000);
// Display getting out of bed animation
lcd.clear();
lcd.setCursor(i, 0);
lcd.write(byte(0)); // Display bed character
lcd.setCursor(6, 0);
lcd.write(byte(1)); // Display person getting out of bed character
lcd.setCursor(1+i, 1);
lcd.print("Getting up...");
delay(1000);
}
}