/*
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
#define PIR_sensor 7
#define NTC_sensor A0
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
pinMode(PIR_sensor, INPUT);
pinMode(NTC_sensor, INPUT);
tft.begin();
tft.setCursor(26, 80);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Hello, TFT!");
// Meme reference: https://english.stackexchange.com/questions/20356/origin-of-i-can-haz
}
void loop() {
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
int pir_state = digitalRead(PIR_sensor);
Serial.println(pir_state);
if (pir_state == HIGH){
tft.setCursor(26, 120);
tft.setTextSize(3);
tft.println("Temperatura");
tft.setCursor(26, 160);
tft.setTextSize(2);
tft.println(celsius);
}
else{
tft.fillScreen(ILI9341_BLACK); // Clear the screen with black color
tft.setCursor(26, 80);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Hello, TFT!");
}
}