#include <LedControl.h>
#include <LiquidCrystal_I2C.h>
#define DATA_IN 11
#define CLK 13
#define CS 10
#define BUTTON_PIN 2
LedControl lc = LedControl(DATA_IN, CLK, CS, 1);
LiquidCrystal_I2C lcd(0x27, 20, 4);
int bstate = 0;
int lastbstate = 1;
bool animation = false;
unsigned long msg = 0;
const unsigned long duration = 5000;
const byte heart1[8] = {
B00000000,
B01100110,
B11111111,
B11111111,
B11111111,
B01111110,
B00111100,
B00011000
};
const byte heart2[8] = {
B01100110,
B11111111,
B11111111,
B11111111,
B01111110,
B00111100,
B00011000,
B00000000
};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 5);
lc.clearDisplay(0);
lcd.begin(20, 4);
lcd.backlight();
lcd.clear();
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
bstate = digitalRead(BUTTON_PIN);
if (bstate == LOW && lastbstate == HIGH) {
animation = true;
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Happy 14 months");
lcd.setCursor(0, 1);
lcd.print("to us, baby! I love");
lcd.setCursor(0, 2);
lcd.print("you so so much! lets");
lcd.setCursor(0, 3);
lcd.print("enjoy our day, oki?");
msg = millis();
}
lastbstate = bstate;
if (animation) {
displayHeart(heart1);
delay(300);
displayHeart(heart2);
delay(300);
if (millis() - msg >= duration) {
lcd.clear();
animation = false;
lc.clearDisplay(0);
}
}
}
void displayHeart(const byte heart[]) {
for (int row = 0; row < 8; row++) {
lc.setRow(0, row, heart[row]);
}
}