/*
Simple "Hello World" for ILI9341 LCD
https://wokwi.com/arduino/projects/308024602434470466
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); //240x320px
#define xEnd 240
#define yEnd 320
#define BLACK 0x0000
#define NAVY 0x000F
#define DARKGREEN 0x03E0
#define DARKCYAN 0x03EF
#define MAROON 0x7800
#define PURPLE 0x780F
#define OLIVE 0x7BE0
#define LIGHTGREY 0xC618
#define DARKGREY 0x7BEF
#define BLUE 0x001F
#define GREEN 0x07E0
#define CYAN 0x07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFD20
#define GREENYELLOW 0xAFE5
#define PINK 0xF81F
unsigned long startTime = millis();
unsigned long lastWrite;
int c;
void setup() {
tft.begin();
tft.fillScreen(DARKGREY);
tft.fillRect(0, 0.35 * yEnd, xEnd, 5, BLACK);
tft.fillRect(.5 * xEnd, 0.1 * yEnd, 5, 0.25 * yEnd, BLACK);
tft.fillRect(0, 0.58 * yEnd, xEnd, 5, BLACK);
tft.fillRect(0, 0.85 * yEnd, xEnd, 5, BLACK);
addText(.2 * xEnd, 5, WHITE, 3, "Humidity");
addText(.7 * xEnd, .12 * yEnd, WHITE, 2, "Set: ");
addText(.05 * xEnd, .12 * yEnd, WHITE, 2, "Actual: ");
addText(.1 * xEnd, .92 * yEnd, WHITE, 2, "(*) SETTINGS (*) ");
// Meme reference: https://english.stackexchange.com/questions/20356/origin-of-i-can-haz
}
void loop() {
if (millis() - startTime < 3000) {
addText(.25 * xEnd, .45 * yEnd, RED, 3, "FAN OFF ");
lastWrite = millis();
} else if (millis() - startTime > 3000 && millis() - startTime < 10000 && c != 1) {
c = 1;
tft.fillRect(.25 * xEnd, .45 * yEnd, xEnd, .1 * yEnd, DARKGREY);
addText(.25 * xEnd, .45 * yEnd, GREEN, 3, "FAN ON");
lastWrite = millis();
} else if (millis() - startTime > 10000) {
if (millis() - lastWrite >= 1000) {
c += 1;
String m = String(c);
tft.fillRect(.8 * xEnd, .4 * yEnd, xEnd, 40, DARKGREY);
tft.setTextColor(GREEN, DARKGREY);
addText(.80 * xEnd, .45 * yEnd, GREEN, 3, m);
lastWrite = millis();
}
}
}
void addText(int xStart, int yStart, unsigned long textColor, byte textSize, String message) {
tft.setCursor(xStart, yStart);
tft.setTextColor(textColor);
tft.setTextSize(textSize);
tft.println(message);
}