#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Custom colors
#define ILI9341_PINK 0xF81F
#define COLOR_TOP 0xF6F5 // #EEBD89
#define COLOR_BOTTOM 0xCA9D // #D13ABD
const char* messages[] = {
"to the love of my life,",
"happy 23rd to us, baby!",
"time flies so fast, mahal. isang buwan na lang, second anniversary na natin. feels like kahapon lang tayo nagkakilala at nagkita.",
"talking to you again was one of the best decisions i have ever made sa buhay ko. i got to know you more, and more importantly,",
"i got to be your girlfriend. i got to love you",
"thank you for staying, mahal. alam kong hindi ako madaling i-handle, and i make a lot of mistakes din",
"pero andiyan ka, laging umiintindi at laging willing habaan ang pasensya",
"you're my safest place, baby. sayo, i can do things i am usually afraid to do when i am with other people. sayo, komportable ako.",
"i love you so much, baby. words are not enough to express how grateful i am na nagkausap ulit tayo,",
"at nag-lead yon sa atin sa situation at relationship na meron tayo ngayon.",
"i can proudly say na pinaka swerte akong tao. baby, kahit gaano pa ka-chaotic ang mundo.",
"i will keep going, and one of the reasons is you."
};
const int numMessages = sizeof(messages) / sizeof(messages[0]);
void setup() {
tft.begin();
tft.setRotation(1);
tft.setTextSize(2);
}
void loop() {
for (int i = 0; i < numMessages; i++) {
drawVerticalGradient(COLOR_TOP, COLOR_BOTTOM);
if (i == 0) {
centerText(messages[i], ILI9341_CYAN);
} else if (i == 1) {
centerText(messages[i], ILI9341_RED);
} else {
printWrappedMessage(messages[i]);
}
delay(6000);
}
delay(8000);
}
void centerText(const char* msg, uint16_t color) {
int16_t x1, y1;
uint16_t w, h;
tft.setTextSize(2);
tft.getTextBounds(msg, 0, 0, &x1, &y1, &w, &h);
int x = (tft.width() - w) / 2;
int y = (tft.height() - h) / 2;
tft.setCursor(x, y);
tft.setTextColor(color);
tft.println(msg);
}
void printWrappedMessage(const char* text) {
int maxWidth = tft.width() - 20;
int lineHeight = 20;
tft.setTextSize(2);
tft.setTextWrap(false);
String lines[20];
int lineCount = 0;
String line = "";
String word = "";
for (int i = 0;; i++) {
char c = text[i];
if (c == ' ' || c == '\0') {
String testLine = line + word;
int16_t x1, y1;
uint16_t w, h;
tft.getTextBounds(testLine.c_str(), 0, 0, &x1, &y1, &w, &h);
if (w > maxWidth && line.length() > 0) {
lines[lineCount++] = line;
line = word;
} else {
line += word;
}
if (c == '\0') break;
word = " ";
} else {
word += c;
}
}
if (line.length() > 0) {
lines[lineCount++] = line;
}
int totalHeight = lineCount * lineHeight;
int startY = (tft.height() - totalHeight) / 2;
for (int i = 0; i < lineCount; i++) {
int x = (tft.width() - getLineWidth(lines[i])) / 2;
printColoredLine(lines[i], x, startY + i * lineHeight);
}
}
void printColoredLine(String line, int x, int y) {
tft.setCursor(x, y);
String word = "";
for (int i = 0; i <= line.length(); i++) {
char c = line[i];
if (c == ' ' || i == line.length()) {
String check = word;
check.toLowerCase();
uint16_t color = (check.indexOf("baby") != -1 || check.indexOf("mahal") != -1)
? ILI9341_PINK : ILI9341_WHITE;
tft.setTextColor(color);
tft.print(word);
if (c == ' ') tft.print(" ");
word = "";
} else {
word += c;
}
}
}
int getLineWidth(String line) {
int16_t x1, y1;
uint16_t w, h;
tft.getTextBounds(line.c_str(), 0, 0, &x1, &y1, &w, &h);
return w;
}
void drawVerticalGradient(uint16_t topColor, uint16_t bottomColor) {
int h = tft.height();
int w = tft.width();
for (int y = 0; y < h; y++) {
float ratio = (float)y / (h - 1);
uint8_t r = ((topColor >> 11) * (1 - ratio) + (bottomColor >> 11) * ratio) * 255 / 31;
uint8_t g = (((topColor >> 5) & 0x3F) * (1 - ratio) + ((bottomColor >> 5) & 0x3F) * ratio) * 255 / 63;
uint8_t b = ((topColor & 0x1F) * (1 - ratio) + (bottomColor & 0x1F) * ratio) * 255 / 31;
uint16_t color = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
// fill an entire horizontal line
tft.fillRect(0, y, w, 1, color); // Make sure it starts at x=0 and spans full width
}
}