#include <Adafruit_GFX.h> // include Adafruit graphics library
#include <Adafruit_ILI9341.h> // include Adafruit ILI9341 TFT library
#define TFT_CS 8 // TFT CS pin is connected to Arduino pin 8
#define TFT_RST 9 // TFT RST pin is connected to Arduino pin 9
#define TFT_DC 10 // TFT DC pin is connected to Arduino pin 10
// Initialize ILI9341 TFT library
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(9600);
Serial.println("ILI9341 Test!");
tft.begin();
tft.fillScreen(ILI9341_BLACK); // Clear screen initially
}
void loop() {
// Alternate between typing and blinking animations
typingAnimation();
delay(1000); // Delay between typing and blinking animations
blinkingAnimation();
delay(1000); // Delay before starting the typing animation again
}
// Function to display text with animation (letter by letter)
void typingAnimation() {
const char* line1 = "MABUHAY";
const char* line2 = "ANG COET";
tft.fillScreen(ILI9341_BLACK); // Clear the screen before typing
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(5);
// Display the first line letter by letter with spacing
tft.setCursor(0, 0);
for (int i = 0; line1[i] != '\0'; i++) {
tft.print(line1[i]);
delay(100); // Adjust delay for animation speed
}
// Pause between lines
delay(500);
// Display the second line letter by letter with spacing
tft.setCursor(0, 50); // Add spacing by adjusting the Y-coordinate (increase it)
for (int i = 0; line2[i] != '\0'; i++) {
tft.print(line2[i]);
delay(100); // Adjust delay for animation speed
}
delay(1000); // Pause before switching to blinking
}
// Function to make the whole text blink (re-type and clear)
void blinkingAnimation() {
const char* line1 = "MABUHAY";
const char* line2 = "ANG COET";
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(5);
// Display the full text with spacing
tft.fillScreen(ILI9341_BLACK); // Clear the screen
tft.setCursor(0, 0);
tft.println(line1);
tft.setCursor(0, 50); // Adjusted Y-coordinate for spacing
tft.println(line2);
delay(1000); // Wait before clearing the screen
// Clear the screen to create the blink effect
tft.fillScreen(ILI9341_BLACK);
delay(500); // Wait before re-typing the text
// Re-display the full text with spacing
tft.setCursor(0, 0);
tft.println(line1);
tft.setCursor(0, 50); // Adjusted Y-coordinate for spacing
tft.println(line2);
delay(1000); // Wait before clearing the screen again
// Clear the screen again to simulate the blinking effect
tft.fillScreen(ILI9341_BLACK);
delay(500); // Wait before re-typing again
}