#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// ----- TFT Pins (ESP32 compatible) -----
#define TFT_CS 15
#define TFT_DC 2
#define TFT_RST 4
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// ----- Emergency Button Pin -----
const int emergencyButton = 12;
int lastButtonState = HIGH;
void setup() {
Serial.begin(115200);
// Button setup
pinMode(emergencyButton, INPUT_PULLUP);
// TFT setup
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(10, 10);
tft.println("System Active 🔵");
Serial.println("System Active - Waiting for Emergency Button");
}
void loop() {
int buttonState = digitalRead(emergencyButton);
// Detect falling edge (button pressed)
if(buttonState == LOW && lastButtonState == HIGH) {
Serial.println("ALERT: Emergency Button Pressed!");
// Display on TFT
tft.fillRect(0, 40, 320, 40, ILI9341_BLACK);
tft.setCursor(10, 40);
tft.setTextColor(ILI9341_RED);
tft.println("EMERGENCY ALERT! 🔴");
}
lastButtonState = buttonState;
}