#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define BTN_PIN 5
#define TFT_DC 2
#define TFT2_DC 32
#define TFT_CS 15
#define TFT2_CS 33
#define BTN1_PIN 25
#define BTN2_PIN 26
#define BTN3_PIN 27
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Adafruit_ILI9341 tft2 = Adafruit_ILI9341(TFT2_CS, TFT2_DC);
bool isOccupied = false;
uint16_t occupiedBgColor = ILI9341_BLACK;
void setup() {
Serial.begin(115200);
pinMode(BTN_PIN, INPUT_PULLUP);
pinMode(BTN1_PIN, INPUT_PULLUP);
pinMode(BTN2_PIN, INPUT_PULLUP);
pinMode(BTN3_PIN, INPUT_PULLUP);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft2.begin();
tft2.setRotation(1);
tft2.fillScreen(ILI9341_BLACK);
drawSign();
}
void loop() {
if (digitalRead(BTN_PIN) == LOW) {
delay(50); // Debounce delay
if (digitalRead(BTN_PIN) == LOW) {
isOccupied = !isOccupied;
drawSign();
while (digitalRead(BTN_PIN) == LOW) {
delay(50); // Wait for button release
}
}
}
if (digitalRead(BTN1_PIN) == LOW) {
delay(50); // Debounce delay
if (digitalRead(BTN1_PIN) == LOW) {
occupiedBgColor = ILI9341_PINK; // 핑크색 배경 설정
drawSign();
while (digitalRead(BTN1_PIN) == LOW) {
delay(50); // Wait for button release
}
}
}
if (digitalRead(BTN2_PIN) == LOW) {
delay(50); // Debounce delay
if (digitalRead(BTN2_PIN) == LOW) {
occupiedBgColor = ILI9341_BLUE; // 파랑색 배경 설정
drawSign();
while (digitalRead(BTN2_PIN) == LOW) {
delay(50); // Wait for button release
}
}
}
if (digitalRead(BTN3_PIN) == LOW) {
delay(50); // Debounce delay
if (digitalRead(BTN3_PIN) == LOW) {
occupiedBgColor = ILI9341_PURPLE; // 보라색 배경 설정
drawSign();
while (digitalRead(BTN3_PIN) == LOW) {
delay(50); // Wait for button release
}
}
}
}
void drawSign() {
if (isOccupied) {
tft.fillScreen(occupiedBgColor); // Occupied 상태일 때 배경 색상 변경
tft.setTextColor(ILI9341_WHITE);
delay(10);
tft2.fillScreen(occupiedBgColor); // Occupied 상태일 때 배경 색상 변경
tft2.setTextColor(ILI9341_WHITE);
} else {
tft.fillScreen(ILI9341_BLACK); // Vacant 상태일 때 배경을 검정색으로 설정
tft.setTextColor(ILI9341_GREEN);
tft2.fillScreen(ILI9341_BLACK); // Occupied 상태일 때 배경 색상 변경
tft2.setTextColor(ILI9341_WHITE);
occupiedBgColor = ILI9341_BLACK;
}
tft.setTextSize(4);
tft.setCursor(40, 100);
tft2.setTextSize(4);
tft2.setCursor(40, 100);
if (isOccupied) {
tft.print("Occupied");
tft2.print("Sign");
} else {
tft.print("Vacant");
tft2.print("WHY");
}
}