#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the I2C address and LCD dimensions
//const String bottomRowText = "Soumen's Playground";
// Custom battery icon characters
byte batteryIcons[5][8] = {
{
B11111,
B10001,
B10001,
B10001,
B10001,
B10001,
B10001,
B11111
},
{
B11111,
B10001,
B10001,
B10001,
B10001,
B10001,
B11111,
B11111
},
{
B11111,
B10001,
B10001,
B10001,
B10001,
B11111,
B11111,
B11111
},
{
B11111,
B10001,
B10001,
B10001,
B11111,
B11111,
B11111,
B11111
},
{
B11111,
B10001,
B10001,
B11111,
B11111,
B11111,
B11111,
B11111
}
};
void setup() {
lcd.begin(16, 2); // Initialize the LCD
for (int i = 0; i <= 5; ++i) {
lcd.createChar(i, batteryIcons[i]); // Create custom characters for battery icons
}
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0); // Set the cursor to the beginning
}
void loop() {
displayBatteryAnimation(); // Call the function to display the battery animation on the upper row
flashBottomRow(); // Call the function to flash text on the bottom row
}
void displayBatteryAnimation() {
static int batteryLevel = 4;
lcd.clear(); // Clear the LCD
// Display the battery icon on the upper row
lcd.setCursor(0, 0);
lcd.write(byte(batteryLevel)); // Display the custom character based on battery level
lcd.print(" ");
// Update the battery level for animation
batteryLevel = (batteryLevel - 1 + 5) % 5;
delay(100); // Adjust the delay for the animation speed
}
void flashBottomRow() {
lcd.setCursor(0, 1); // Set the cursor to the beginning of the bottom row
//lcd.print(bottomRowText);
delay(100); // Interval for flashing text
lcd.clear(); // Clear the bottom row
delay(100); // Interval for a blank display
}