//#include <WiFi.h>
//#include <HTTPClient.h>
//#include <ArduinoJson.h>
//#include <Adafruit_GFX.h>
//#include <Adafruit_ILI9341.h>
#include "display.h"
#define BTN_PIN 5
#define TFT_DC 2 // TFT SPI data or command selector pin
#define TFT_CS 15 // TFT SPI chip select pin
#define TFT_RST 4
#if 0
int temperature_gen(){
int arr[] = {23, 24, 25, 26, 27, 28, 29, 30, 31, 32};
return arr[rand()%10];
}
class Display {
public:
Display(int btnPin, int tftDC, int tftCS, int tftRST) : btnPin(BTN_PIN), tft(TFT_CS, TFT_DC, TFT_RST) {
}
void initialize() {
pinMode(btnPin, INPUT_PULLUP);
tft.begin();
tft.setCursor(30, 50);
tft.setRotation(1);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Getting started.....");
/*while (WiFi.status() != WL_CONNECTED) {
delay(100);
tft.print(".");
}*/
tft.print("\nPress the Push Button");
//tft.println(WiFi.localIP());
}
void print_tft(int val){
tft.print("\n Temperature sensor value: ");
tft.print(val);
tft.println(" C");
}
int temperature_gen(){
int arr[] = {23, 24, 25, 26, 27, 28, 29, 30, 31, 32};
return arr[rand()%10];
}
void reset_tft(){
pinMode(TFT_RST, OUTPUT);
digitalWrite(TFT_RST, LOW);
delay(100);
digitalWrite(TFT_RST, HIGH);
delay(100);
}
void loop_1() {
if (digitalRead(btnPin) == LOW) {
//tft.reset();
reset_tft();
tft.fillScreen (0x0000);
//tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.setRotation(1);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.println("\nLoading screen...");
delay(100);
tft.println("\nButton pressed.");
print_tft(temperature_gen());
}
delay(100);
}
private:
int btnPin;
Adafruit_ILI9341 tft;
};
#endif
//const char* ssid = "Wokwi-GUEST";
//const char* password = "";
void setup() {
//WiFi.begin(ssid, password, 6);
Display display(BTN_PIN, TFT_DC, TFT_CS, TFT_RST);
display.initialize();
}
void loop() {
Display display(BTN_PIN, TFT_DC, TFT_CS,TFT_RST);
display.loop_1();
//display.print_tft(temperature_gen());
}