#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <Servo.h>
// Servo motor setup
Servo rocketServo;
int servoPin = 9;
// Fingerprint recognition variables
int authorizedButtonPin = 2; // Button for authorized fingerprint
int unauthorizedButtonPin = 3; // Button for unauthorized fingerprint
bool fingerprintAuthorized;
// Define the pins for the TFT display
#define TFT_SCK 13
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_CS 10
#define TFT_DC 8
// Create an instance of the TFT display
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCK, TFT_MISO);
// LED pin
int ledPin = 6;
void setup() {
// Initialize TFT display
tft.begin();
// Initialize servo
rocketServo.attach(servoPin);
// Initialize fingerprint buttons
pinMode(authorizedButtonPin, INPUT_PULLUP);
pinMode(unauthorizedButtonPin, INPUT_PULLUP);
// Initialize LED pin
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // Turn off LED
// Initialize serial communication for debugging
Serial.begin(9600);
// Display initial message
displayMessage("Scanning...", ILI9341_WHITE); // Initial message is white
}
void loop() {
// Check if the authorized fingerprint button is pressed
if (digitalRead(authorizedButtonPin) == LOW) {
fingerprintAuthorized = true;
Serial.println("Authorized fingerprint detected!");
displayMessage("FINGERPRINT AUTHORIZED!", ILI9341_GREEN); // Authorized message is green
countdownAndLaunch();
}
// Check if the unauthorized fingerprint button is pressed
if (digitalRead(unauthorizedButtonPin) == LOW) {
fingerprintAuthorized = false;
Serial.println("Unauthorized fingerprint detected!");
displayMessage("ACCESS DENIED", ILI9341_RED); // Unauthorized message is red
}
}
void countdownAndLaunch() {
for (int count = 3; count > 0; count--) {
displayCountdown(count);
}
displayMessage("BLAST OFF!", ILI9341_YELLOW);
rocketServo.write(0);
delay(1000);
digitalWrite(ledPin, HIGH);
delay(5000);
rocketServo.write(90);
digitalWrite(ledPin, LOW);
fingerprintAuthorized = false;
}
void displayMessage(const char* message, uint16_t textColor) {
tft.fillScreen(ILI9341_BLACK); // Clear the screen
tft.setCursor(35, 100); // Adjust coordinates as needed
tft.setTextColor(textColor);
tft.setTextSize(3);
tft.println(message);
}
void displayCountdown(int count) {
tft.fillScreen(ILI9341_BLACK); // Clear the screen
tft.setCursor(60, 50); // Adjust coordinates as needed
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(20);
tft.print(count);
}