#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// Global variables for small vertical line
int smallVerticalLineX;
int smallVerticalLineHeight;
int PMSensor = 34;
int test = 0;
int test2 = 250;
int test3 = 354;
void setup() {
Serial.begin(9600);
tft.begin();
tft.setRotation(1); // Set rotation to 3
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
// Draw a box that fills the entire screen with a gap of gapSize
int gapSize = 22; // Adjust the size of the gap
int lineDistance = -10; // Adjust the distance of the lines from the box
int boxX = gapSize;
int boxY = gapSize;
int boxWidth = tft.width() - 2 * gapSize;
int boxHeight = tft.height() - 2 * gapSize;
// RGB values for light blue (adjust as needed)
int boxColor = tft.color565(173, 216, 230);
tft.drawRect(boxX, boxY, boxWidth, boxHeight, boxColor);
// Draw a horizontal line at the top with a gap of gapSize
int topLineY = boxY + gapSize - lineDistance;
tft.drawFastHLine(boxX, topLineY, boxWidth, boxColor);
// Draw a horizontal line at the bottom with a gap of gapSize
int bottomLineY = boxY + boxHeight - gapSize + lineDistance;
tft.drawFastHLine(boxX, bottomLineY, boxWidth, boxColor);
int middleX = boxX + boxWidth * 6 / 10;
tft.drawFastVLine(middleX, topLineY, bottomLineY - topLineY, boxColor);
// Draw a horizontal line from the left to the vertical line, 2/3 of the box height
int leftLineX = boxX;
int leftLineY = boxY + boxHeight * 3 / 5;
int lineLength = middleX - leftLineX;
tft.drawFastHLine(leftLineX, leftLineY, lineLength, boxColor);
// Print text on the screen
tft.setTextSize(1.2);
tft.setCursor(58, 35);
tft.print("AIR PURIFIER AND MONITORING SYSTEM");
tft.setTextSize(1.2);
tft.setCursor(30, 60);
tft.print("PM2.5 :");
tft.setCursor(110, 145);
tft.print("PM1 :");
tft.setCursor(30, 145);
tft.print("PM10 :");
tft.setTextSize(1.5);
tft.setCursor(195, 60);
tft.print("AQI:");
tft.fillRect(138, 208, 127, 12, ILI9341_WHITE);
tft.fillRect(140, 205, 25, 8, ILI9341_GREEN);
tft.fillRect(165, 205, 25, 8, ILI9341_YELLOW);
tft.fillRect(190, 205, 25, 8, tft.color565(255, 165, 0));
tft.fillRect(215, 205, 25, 8, ILI9341_RED);
tft.fillRect(240, 205, 25, 8, tft.color565(128, 0, 0));
}
void loop() {
Screen();
ColourScreen();
delay(100);
}
void Screen() {
int sensorValue = analogRead(PMSensor);
// Convert sensor value to a string
String sensorString = String(sensorValue);
test = test + 50;
delay(2500);
if(test > 350) {
test = 0;
}
tft.fillRect(65, 80, 90, 50, ILI9341_BLACK);
tft.fillRect(130, 160, 34, 15, ILI9341_BLACK);
tft.fillRect(50, 160, 34, 15, ILI9341_BLACK);
tft.fillRect(200, 80, 80, 60, ILI9341_BLACK);
// Display the sensor value on the screen
tft.setTextSize(5);
tft.setTextColor(ILI9341_WHITE); // Set text color explicitly
tft.setCursor(65, 80);
tft.print(test);
tft.setTextSize(2.2);
tft.setTextColor(ILI9341_WHITE); // Set text color explicitly
tft.setCursor(130, 160);
tft.print(test);
tft.setTextSize(2.2);
tft.setTextColor(ILI9341_WHITE); // Set text color explicitly
tft.setCursor(50, 160);
tft.print(test);
tft.setTextSize(4);
tft.setTextColor(ILI9341_WHITE); // Set text color explicitly
tft.setCursor(210, 85);
tft.print(test);
delay(2000);
}
void ColourScreen() {
if (test < 50) {
tft.fillRect(30, 200, 60, 10, ILI9341_BLACK);
tft.setCursor(30, 200);
tft.setTextSize(1.8);
tft.setTextColor(ILI9341_GREEN);
tft.print("Good");
}
if (test > 50) {
tft.fillRect(30, 200, 60, 10, ILI9341_BLACK);
tft.setCursor(30, 200);
tft.setTextSize(1.8);
tft.setTextColor(ILI9341_YELLOW);
tft.print("Mild");
}
if (test > 100) {
tft.fillRect(30, 200, 60, 10, ILI9341_BLACK);
tft.setCursor(30, 200);
tft.setTextSize(1.8);
tft.setTextColor(tft.color565(255, 165, 0)); // Assign color using color565()
tft.print("Moderate");
}
if (test > 150) {
tft.fillRect(30, 200, 60, 10, ILI9341_BLACK);
tft.setCursor(30, 200);
tft.setTextSize(1.8);
tft.setTextColor(ILI9341_RED);
tft.print("Severe");
}
if (test > 200) {
tft.fillRect(30, 200, 60, 10, ILI9341_BLACK);
tft.setCursor(30, 200);
tft.setTextSize(1.8);
tft.setTextColor(tft.color565(128, 0, 128)); // Assign color using color565()
tft.print("Unhealthy");
}
if (test > 300) {
tft.fillRect(30, 200, 60, 10, ILI9341_BLACK);
tft.setCursor(30, 200);
tft.setTextSize(1.8);
tft.setTextColor(tft.color565(128, 0, 0)); // Assign color using color565()
tft.print("Hazardous");
}
}