#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// Pins for the ILI9341
#define TFT_CS 10
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 8
#define TFT_MOSI 11
#define TFT_SCLK 13
#define TFT_MISO 12
// Initialize ILI9341 screen
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Function to center text horizontally
int16_t getCenteredX(const char* text, int textSize) {
int16_t x1, y1;
uint16_t w, h;
tft.setTextSize(textSize);
tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
return (tft.width() - w) / 2;
}
// Function to display text
void displayText() {
// Set text size
int textSize = 2;
int yOffset = 120; // Adjust this value to move all text downward
// Clear the screen with a background color
tft.fillScreen(ILI9341_BLACK);
// Display the date in red
tft.setTextColor(ILI9341_RED);
tft.setCursor(getCenteredX("23/9/2024", textSize), yOffset + 0);
tft.print("23/9/2024");
// Display "HAPPY BIRTHDAY" in blue
tft.setTextColor(ILI9341_BLUE);
tft.setCursor(getCenteredX("HAPPY BIRTHDAY", textSize), yOffset + 40);
tft.print("HAPPY BIRTHDAY");
// Display "SHAFA CARMELIA" in pink
tft.setTextColor(ILI9341_PINK);
tft.setCursor(getCenteredX("SHAFA CARMELIA", textSize), yOffset + 80);
tft.print("SHAFA CARMELIA");
}
// Function to display an image from the SD card
void displayImage(const char* filename) {
// Note: Implementation to load and display the image from SD card should be added here
// Placeholder: Fill the screen with a random color for demonstration
uint16_t colors[] = {ILI9341_RED, ILI9341_GREEN, ILI9341_BLUE, ILI9341_YELLOW, ILI9341_CYAN};
static int colorIndex = 0;
tft.fillScreen(colors[colorIndex % 5]);
colorIndex++;
}
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Initialize the display
tft.begin();
Serial.println("Display initialized");
// Rotate the display to portrait mode
tft.setRotation(0);
// Clear the screen with a background color
tft.fillScreen(ILI9341_BLACK);
}
void loop() {
// Array of image filenames (if using SD card)
const char* images[] = {"image1.bmp", "image2.bmp", "image3.bmp", "image4.bmp", "image5.bmp"};
int numImages = 5;
// Loop through the images
for (int i = 0; i < numImages; i++) {
displayImage(images[i]);
delay(2000); // Display each image for 2 seconds
}
// Display text
displayText();
delay(2000); // Display text for 2 seconds
}