Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //**************************************************************************************
- // Code voor een wifi thermostaat met een DHT sensor (11 of 22) en touchscreen TFT **
- //**************************************************************************************
- //ESPWebtime code voor het ophalen van tijd via
- #include <NTPClient.h>
- #include <ESP8266WiFi.h>
- #include <WiFiUdp.h>
- const char * ssid = "";
- const char * password = "";
- const long utcOffsetInSeconds = 3600;
- // Define NTP Client to get time
- WiFiUDP ntpUDP;
- NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
- #include <SPI.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_ILI9341.h>
- #include <XPT2046_Touchscreen.h>
- #define TFT_CS D0 //for D1 mini or TFT I2C Connector Shield (V1.1.0 or later)
- #define TFT_DC D8 //for D1 mini or TFT I2C Connector Shield (V1.1.0 or later)
- #define TFT_RST - 1 //for D1 mini or TFT I2C Connector Shield (V1.1.0 or later)
- #define TS_CS D3 //for D1 mini or TFT I2C Connector Shield (V1.1.0 or later)
- // #define TFT_CS 14 //for D32 Pro
- // #define TFT_DC 27 //for D32 Pro
- // #define TFT_RST 33 //for D32 Pro
- // #define TS_CS 12 //for D32 Pro
- Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
- XPT2046_Touchscreen ts(TS_CS);
- #include <DHT.h> // DHT sensor (temp en luchtvochtigheid)
- // Fonts https://rop.nl/truetype2gfx/
- #include <Fonts/Segment10pt7b.h>
- #include <Fonts/Segment18pt7b.h>
- #include <Fonts/Segment22pt7b.h>
- #include <Fonts/Segment48pt7b.h>
- #include <Fonts/icons14pt7b.h>
- #include <Fonts/icons30pt7b.h>
- //DHT sensor
- #define DHTPIN D4
- #define DHTTYPE DHT11
- //Vertalen
- #define TS_MINX 230
- #define TS_MAXX 3600
- #define TS_MINY 330
- #define TS_MAXY 3700
- //https://github.com/wemos/D1_mini_Examples/blob/master/examples/04.Shields/TFT_2.4_Touch_Shield/TFT_TouchTest/TFT_TouchTest.ino
- DHT dht(DHTPIN, DHTTYPE);
- // 16-bit kleuren definities: https://ee-programming-notepad.blogspot.com/2016/10/16-bit-color-generator-picker.html
- #define BLACK 0x0000
- #define WHITE 0xFFFF
- #define BUTTONBG 0xFFFF
- #define BUTTONEDGE 0x9492
- #define TEXTCOLOR 0x0000
- #define SCREENCOLOR 0xFFFF
- #define TOGGLEON 0x53C9
- #define TOGGLEOFF 0xDEFB
- #define HEATON 0xD1E3
- #define HEATOFF 0xDEFB
- #define WIFION 0x0000
- #define WIFIOFF 0xD1E3
- //Drukbereik touchscreen
- #define MINPRESSURE 400
- #define MAXPRESSURE 3000
- // Variabelen
- unsigned long currentTimeMillis = millis();
- unsigned long previousTimeMillis;
- unsigned long currentScreenTimOuteMillis = millis();
- unsigned long previousScreenTimeOutMillis;
- int TimeOutPeriod = 20000; //Timeout voor het dimmen van het scherm
- int DimMode = 1; //1= helder, 2 = gedimd, 3 = nachtscherm, 4 = uit
- float TempSet = 14; //Ingestelde temperatuur
- float PrevTempSet;
- int D = 1;
- String DD = "Ma";
- String DayNames[7] = {"Zo","Ma","Di","Wo","Do","Vr","Za"};
- int H = 112; // Uren binnen honderd (om de eerste 1 er weer vanaf te kunnen knippen)
- int M = 100; // Minuten
- String HH;
- String MM;
- String DisplayTime;
- String PrevDisplayTime;
- float Temp = dht.readTemperature();
- float PrevTemp;
- int Humid = dht.readHumidity();
- int PrevHumid;
- String RecieveFromSerial;
- String TimePartH;
- String TimePartM;
- int HeatState = 0;
- int PrevHeatState = 2;
- int power1 = 0;
- int power2 = 0;
- int DisplayScreen = 1;
- int PrevDisplayScreen = 0;
- int ScreenTouch = 0;
- int Toggle1 = 0;
- int Toggle2 = 0;
- int PrevToggle1 = 2;
- int PrevToggle2 = 2;
- int WifiStatus = 0;
- int PrevWifiStatus = 2;
- int HeatingMode = 3; //1=automatisch 2=uitschakeltimer 3=handmatig
- //schermconfiguratie
- //Icoontjes: z Power, O sun high, Q Sun low, k clock, = Wifi, ! error, V checkbox checked, W checkbox empty, U Unlocked, L Locked, d Settings, F WaterDrop, 4 up, ~ down, β¬ β¬, B Menu btn, h Menu open, , arrow < , . arrow >, Y Pin
- int MenuBtnX = 140;
- int MenuBtnY = 210;
- int CurTempX = 5;
- int CurTempY = 50;
- String TitleCurTemp = "";
- int SetTempX = 0;
- int SetTempY = 100;
- String TitleSetT = "";
- int CurTemp2X = 110;
- int CurTemp2Y = 50;
- String TitleCurTemp2 = "";
- int SetTemp2X = 62;
- int SetTemp2Y = 100;
- String TitleSetT2 = "";
- int UpBtnX = 260;
- int UpBtnY = 120;
- char UpBtnIcon = '+';
- int DwnBtnX = 10;
- int DwnBtnY = 120;
- char DwnBtnIcon = '~';
- int TimeDisplX = 100;
- int TimeDisplY = 5;
- int HumidX = 5;
- int HumidY = 210;
- String HumidIcon = "F";
- int Toggle1X = 210;
- int Toggle1Y = 30;
- char Toggle1Icon = 'z';
- String Toggle1Title = "";
- int Toggle2X = 210;
- int Toggle2Y = 120;
- char Toggle2Icon = 'z';
- int HeatStateX = 285;
- int HeatStateY = 232;
- char HeatOnIcon = 'O';
- char HeatOffIcon = 'Q';
- int WifiPosX = 10;
- int WifiPosY = 25;
- char WifiOnIcon = '=';
- char WifiOffIcon = '!';
- String MenuOption1 = "Automatisch";
- int MenuOpt1Number = 1;
- String MenuOption2 = "Uitschakeltimer";
- int MenuOpt2Number = 2;
- String MenuOption3 = "Handmatig";
- int MenuOpt3Number = 3;
- String MenuOption4 = "Schema";
- int MenuOpt4Number = 4;
- String MenuOption5 = "Schakelaarklok";
- int MenuOpt5Number = 5;
- String MenuOption6 = "Andere ruimte";
- int MenuOpt6Number = 6;
- void setup() {
- Serial.begin(9600);
- timeClient.begin();
- timeClient.setUpdateInterval(3600000); //Elk uur updaten i.p.v. elke minuut
- dht.begin();
- initDisplay();
- pinMode(D1,OUTPUT);
- digitalWrite(D1,1);
- tft.fillScreen(SCREENCOLOR);
- tft.setTextColor(TEXTCOLOR);
- tft.setFont( & Segment10pt7b);
- tft.setCursor(50, 150);
- tft.print("Verbinden");
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- tft.print(".");
- }
- GetWifiStatus();
- tft.fillScreen(SCREENCOLOR);
- GetTime();
- delay(500);
- }
- void initDisplay() {
- ts.begin();
- ts.setRotation(0);
- tft.begin();
- tft.setRotation(3);
- }
- void ScreenTimeOut(){
- currentScreenTimOuteMillis = millis();
- if (previousScreenTimeOutMillis + TimeOutPeriod < currentScreenTimOuteMillis)
- if ((H-100)*100+(M-100) > 1645){
- digitalWrite(D1,0);
- }
- else {analogWrite(D1,150);}
- }
- void GetWifiStatus() {
- if (WiFi.status() == WL_CONNECTED) {
- WifiStatus = 1;
- } else {
- WifiStatus = 0;
- }
- }
- void DrawWifiStatus(int posX, int posY) {
- if ((WifiStatus != PrevWifiStatus)||(DisplayScreen != PrevDisplayScreen)) {
- tft.fillRect(posX - 4, posY - 20, 35, 35, SCREENCOLOR);
- tft.setCursor(posX, posY);
- tft.setFont( & icons14pt7b);
- if (WifiStatus == 1) {
- tft.setTextColor(WIFION);
- tft.print(WifiOnIcon);
- } else {
- tft.setTextColor(WIFIOFF);
- tft.print(WifiOffIcon);
- }
- PrevWifiStatus = WifiStatus;
- }
- }
- void GetTime() {
- timeClient.update();
- H = timeClient.getHours() + 100;
- M = timeClient.getMinutes() + 100;
- D = timeClient.getDay();
- DD = DayNames[D];
- }
- void DrawHeatState(int posX, int posY) {
- if (DisplayScreen != PrevDisplayScreen){
- PrevHeatState = 2;
- }
- tft.setCursor(posX, posY);
- tft.setFont( & icons14pt7b);
- if (Temp < TempSet) {
- HeatState = 1;
- tft.setTextColor(HEATON);
- if (HeatState != PrevHeatState) {
- tft.fillRect(posX - 4, posY - 20, 35, 35, SCREENCOLOR);
- tft.print(HeatOnIcon);
- PrevHeatState = 1;
- }
- } else {
- HeatState = 0;
- tft.setTextColor(HEATOFF);
- if (HeatState != PrevHeatState) {
- tft.fillRect(posX - 4, posY - 20, 35, 35, SCREENCOLOR);
- tft.print(HeatOffIcon);
- PrevHeatState = 0;
- }
- }
- }
- void ToggleHeating() {
- if (DisplayScreen != PrevDisplayScreen) {
- // getTemp();
- DrawHeatState(HeatStateX, HeatStateY);
- }
- }
- void RecTime() {
- if ((Serial.read()) > (0)) {
- RecieveFromSerial = String(Serial.readStringUntil('\n'));
- if (((RecieveFromSerial.substring(1, 1)) == ("T"))) {
- TimePartH = RecieveFromSerial.substring(0, 2);
- TimePartM = RecieveFromSerial.substring(2, 4);
- H = TimePartH.toInt() + 100;
- M = TimePartM.toInt() + 100;
- DrawTime(TimeDisplX, TimeDisplY);
- }
- }
- }
- void DrawCurTemp(int posX, int posY) {
- getTemp();
- if ((Temp != PrevTemp) || (DisplayScreen != PrevDisplayScreen)) {
- tft.setFont( & Segment10pt7b);
- tft.setCursor(posX, posY - 4);
- tft.setTextColor(TEXTCOLOR);
- tft.print(TitleCurTemp);
- getTemp();
- char T[8];
- dtostrf(Temp, 6, 1, T);
- tft.fillRoundRect(posX, posY, 110, 45, 5, BUTTONBG);
- tft.setTextColor(TEXTCOLOR);
- tft.setFont( & Segment22pt7b);
- tft.setCursor(posX - 25, posY + 42);
- tft.print(T);
- int curposx = tft.getCursorX();
- int curposy = tft.getCursorY();
- tft.setCursor(curposx + 2, curposy - 16);
- tft.setFont( & Segment10pt7b);
- tft.print("o");
- PrevTemp = Temp;
- }
- }
- void DrawSetTemp(int posX, int posY) {
- if ((TempSet != PrevTempSet) || (DisplayScreen != PrevDisplayScreen)) {
- char TsetT[8];
- dtostrf(TempSet, 6, 1, TsetT);
- String TempString = String(TsetT);
- String TempString2 = String(TsetT);
- TempString.replace("1", "");
- tft.setFont( & Segment10pt7b);
- tft.setCursor(SetTempX, SetTempY);
- tft.setTextColor(TEXTCOLOR);
- tft.print(TitleSetT);
- tft.fillRoundRect(posX, posY + 4, 190, 82, 5, BUTTONBG);
- // tft.drawRoundRect(setTposX, setTposY + 4, 190, 82, 5, BUTTONEDGE);
- tft.setTextColor(TEXTCOLOR);
- tft.setFont( & Segment48pt7b);
- //als er een 1 in e temperatuur zit dan is er een andere uitlijning nodig
- if (TempString == TempString2) {
- tft.setCursor(posX - 86, posY + 75);
- } else {
- tft.setCursor(posX - 70, posY + 75);
- }
- tft.print(TsetT);
- int curposx = tft.getCursorX();
- int curposy = tft.getCursorY();
- tft.setCursor(curposx + 2, curposy - 35);
- tft.setFont( & Segment22pt7b);
- tft.print("o");
- PrevTempSet = TempSet;
- }
- }
- void DrawMenuBtn(int posX, int posY) {
- if (DisplayScreen != PrevDisplayScreen) {
- tft.fillRoundRect(posX, posY, 35, 22, 5, BUTTONBG);
- tft.drawRoundRect(posX, posY, 35, 22, 5, BUTTONEDGE);
- tft.setCursor(posX + 5, posY + 10);
- tft.setTextColor(TEXTCOLOR);
- tft.setFont( & Segment22pt7b);
- tft.print("...");
- }
- }
- void DrawMenu() {
- DrawMenuBtn(MenuBtnX, MenuBtnY);
- tft.setTextColor(TEXTCOLOR);
- tft.setFont( & Segment10pt7b);
- int xpos = 5;
- int ypos = 10;
- tft.fillRoundRect(xpos, ypos, 150, 50, 5, BUTTONBG);
- tft.drawRoundRect(xpos, ypos, 150, 50, 5, BUTTONEDGE);
- tft.setCursor(xpos + 10, ypos + 32);
- tft.print(MenuOption1);
- ypos += 65;
- tft.fillRoundRect(xpos, ypos, 150, 50, 5, BUTTONBG);
- tft.drawRoundRect(xpos, ypos, 150, 50, 5, BUTTONEDGE);
- tft.setCursor(xpos + 10, ypos + 32);
- tft.print(MenuOption2);
- ypos += 65;
- tft.fillRoundRect(xpos, ypos, 150, 50, 5, BUTTONBG);
- tft.drawRoundRect(xpos, ypos, 150, 50, 5, BUTTONEDGE);
- tft.setCursor(xpos + 10, ypos + 32);
- tft.print(MenuOption3);
- ypos += 65;
- xpos = 165;
- ypos = 10;
- tft.fillRoundRect(xpos, ypos, 150, 50, 5, BUTTONBG);
- tft.drawRoundRect(xpos, ypos, 150, 50, 5, BUTTONEDGE);
- tft.setCursor(xpos + 10, ypos + 32);
- tft.print(MenuOption4);
- ypos += 65;
- tft.fillRoundRect(xpos, ypos, 150, 50, 5, BUTTONBG);
- tft.drawRoundRect(xpos, ypos, 150, 50, 5, BUTTONEDGE);
- tft.setCursor(xpos + 10, ypos + 32);
- tft.print(MenuOption5);
- ypos += 65;
- tft.fillRoundRect(xpos, ypos, 150, 50, 5, BUTTONBG);
- tft.drawRoundRect(xpos, ypos, 150, 50, 5, BUTTONEDGE);
- tft.setCursor(xpos + 10, ypos + 32);
- tft.print(MenuOption6);
- ypos += 65;
- }
- void DrawToggle1(int PosX, int PosY) {
- if ((Toggle1 != PrevToggle1) || (DisplayScreen != PrevDisplayScreen)) {
- tft.fillRoundRect(PosX, PosY, 80, 80, 15, BUTTONBG);
- tft.drawRoundRect(PosX, PosY, 80, 80, 15, BUTTONEDGE);
- tft.setFont( & icons30pt7b);
- tft.setCursor(PosX + 16, PosY + 55);
- if (Toggle1 == 0) {
- tft.setTextColor(TOGGLEOFF);
- PrevToggle1 = 0;
- tft.print(Toggle1Icon);
- } else {
- tft.setTextColor(TOGGLEON);
- PrevToggle1 = 1;
- tft.print(Toggle1Icon);
- }
- }
- }
- void SetToggle1() {
- if (Toggle1 == 0) {
- Toggle1 = 1;
- } else {
- Toggle1 = 0;
- }
- DrawToggle1(Toggle1X, Toggle1Y);
- }
- void DrawToggle2(int PosX, int PosY) {
- if ((Toggle2 != PrevToggle2) || (DisplayScreen != PrevDisplayScreen)) {
- tft.fillRoundRect(PosX, PosY, 80, 80, 15, BUTTONBG);
- tft.drawRoundRect(PosX, PosY, 80, 80, 15, BUTTONEDGE);
- tft.setFont( & icons30pt7b);
- tft.setCursor(PosX + 16, PosY + 55);
- if (Toggle2 == 0) {
- tft.setTextColor(TOGGLEOFF);
- PrevToggle2 = 0;
- tft.print(Toggle2Icon);
- } else {
- tft.setTextColor(TOGGLEON);
- PrevToggle2 = 1;
- tft.print(Toggle2Icon);
- }
- }
- }
- void SetToggle2() {
- if (Toggle2 == 0) {
- Toggle2 = 1;
- } else {
- Toggle2 = 0;
- }
- DrawToggle2(Toggle2X, Toggle2Y);
- }
- void DrawUpBtn(int posX, int posY) {
- if (DisplayScreen != PrevDisplayScreen) {
- tft.fillRoundRect(posX, posY, 50, 50, 5, BUTTONBG);
- tft.drawRoundRect(posX, posY, 50, 50, 5, BUTTONEDGE);
- tft.setCursor(posX + 12, posY + 37);
- tft.setTextColor(TEXTCOLOR);
- tft.setFont( & Segment22pt7b);
- tft.print("+");
- }
- }
- void DrawDwnBtn(int posX, int posY) {
- if (DisplayScreen != PrevDisplayScreen) {
- tft.fillRoundRect(posX, posY, 50, 50, 5, BUTTONBG);
- tft.drawRoundRect(posX, posY, 50, 50, 5, BUTTONEDGE);
- tft.setCursor(posX + 15, posY + 40);
- tft.setTextColor(TEXTCOLOR);
- tft.setFont( & Segment22pt7b);
- tft.print("-");
- }
- }
- void Clock() {
- currentTimeMillis = millis();
- if ((M) > (159)) {
- M = 100;
- H += 1;
- }
- if ((H) > (123)) {
- H = 100;
- }
- HH = String(H);
- MM = String(M);
- if ((H) > (109)) {
- DisplayTime = String(HH.substring(2 - 1, 3) + String(":") + MM.substring(2 - 1, 3));
- } else {
- DisplayTime = String(HH.substring(3 - 1, 3) + String(":") + MM.substring(2 - 1, 3));
- }
- // DisplayTime = DD + " "+DisplayTime;
- if (currentTimeMillis - previousTimeMillis > 60000) {
- previousTimeMillis = previousTimeMillis + 60000;
- M += 1;
- }
- }
- void DrawTime(int posX, int posY) {
- Clock();
- if ((DisplayTime != PrevDisplayTime) || (DisplayScreen != PrevDisplayScreen)) {
- tft.fillRect(posX, posY, 100, 35, SCREENCOLOR);
- tft.setCursor(posX + 7, posY + 30);
- tft.setTextColor(TEXTCOLOR);
- tft.setFont( & Segment22pt7b);
- tft.print(DisplayTime);
- PrevDisplayTime = DisplayTime;
- }
- }
- void DrawHumid(int posX, int posY) {
- if ((Humid != PrevHumid) || (DisplayScreen != PrevDisplayScreen)) {
- Humid = dht.readHumidity() - 1.4;
- tft.fillRect(posX, posY, 80, 35, SCREENCOLOR);
- tft.setCursor(posX + 6, posY + 22);
- tft.setTextColor(TEXTCOLOR);
- tft.setFont( & icons14pt7b);
- tft.print(HumidIcon);
- tft.setFont( & Segment10pt7b);
- tft.print(" ");
- tft.print(Humid);
- tft.print("%");
- PrevHumid = Humid;
- }
- }
- void TempUp() {
- TempSet = TempSet + 0.5;
- }
- void TempDown() {
- TempSet = TempSet - 0.5;
- }
- void getTemp() {
- Temp = dht.readTemperature() - 1.4;
- }
- void loop() {
- RecTime();
- GetTime();
- ToggleHeating();
- GetWifiStatus();
- ScreenTimeOut();
- if (DisplayScreen != PrevDisplayScreen) {
- tft.fillScreen(SCREENCOLOR);
- }
- unsigned long currentMillis = millis();
- unsigned long previousMillis;
- if (DisplayScreen == 0) {
- if (DisplayScreen != PrevDisplayScreen) {
- DrawMenu();
- PrevDisplayScreen = 0;
- }
- } else if (DisplayScreen == 1) {
- GetWifiStatus();
- DrawWifiStatus(WifiPosX, WifiPosY);
- DrawMenuBtn(MenuBtnX, MenuBtnY);
- DrawCurTemp(CurTempX, CurTempY);
- DrawSetTemp(SetTempX, SetTempY);
- // DrawUpBtn(UpBtnX,UpBtnY);
- // DrawDwnBtn(DwnBtnX,DwnBtnY);
- DrawToggle1(Toggle1X, Toggle1Y);
- DrawToggle2(Toggle2X, Toggle2Y);
- DrawTime(TimeDisplX, TimeDisplY);
- DrawHumid(HumidX, HumidY);
- DrawHeatState(HeatStateX, HeatStateY);
- PrevDisplayScreen = 1;
- } else if (DisplayScreen == 2) {
- GetWifiStatus();
- DrawWifiStatus(WifiPosX, WifiPosY);
- // DrawMenuBtn(MenuBtnX, MenuBtnY);
- DrawCurTemp(CurTemp2X, CurTemp2Y);
- DrawSetTemp(SetTemp2X, SetTemp2Y);
- DrawUpBtn(UpBtnX, UpBtnY);
- DrawDwnBtn(DwnBtnX, DwnBtnY);
- // DrawToggle1(Toggle1X,Toggle1Y);
- // DrawToggle2(Toggle2X,Toggle2Y);
- DrawTime(TimeDisplX, TimeDisplY);
- DrawHumid(HumidX, HumidY);
- DrawHeatState(HeatStateX, HeatStateY);
- PrevDisplayScreen = 2;
- } else if (DisplayScreen == 3) {
- GetWifiStatus();
- DrawWifiStatus(WifiPosX, WifiPosY);
- // DrawMenuBtn(MenuBtnX, MenuBtnY);
- DrawCurTemp(CurTemp2X, CurTemp2Y);
- DrawSetTemp(SetTemp2X, SetTemp2Y);
- DrawUpBtn(UpBtnX, UpBtnY);
- DrawDwnBtn(DwnBtnX, DwnBtnY);
- // DrawToggle1(Toggle1X,Toggle1Y);
- // DrawToggle2(Toggle2X,Toggle2Y);
- DrawTime(TimeDisplX, TimeDisplY);
- DrawHumid(HumidX, HumidY);
- DrawHeatState(HeatStateX, HeatStateY);
- PrevDisplayScreen = 2;
- int BackLight = 0;
- for(int __i__=0;__i__<10;++__i__)
- {
- analogWrite(D1,BackLight);
- BackLight += 25;
- delay(150);
- }
- for(int __i__=0;__i__<10;++__i__)
- {
- analogWrite(D1,BackLight);
- BackLight += -25;
- delay(150);
- }
- analogWrite(D1,255);
- delay(2000);
- digitalWrite(D1,1);
- DisplayScreen = 1;
- }
- //Als het scherm wordt aangeraakt
- if (ts.touched()) {
- previousScreenTimeOutMillis = millis();
- digitalWrite (D1,1);
- TS_Point p = ts.getPoint();
- delay(150);
- //Vertaal de input van het touchscreen naar coordinaten op het scherm
- p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
- p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
- //Knoppen van de Menuopties
- if (DisplayScreen == 0) {
- int xpos = 5;
- int ypos = 10;
- if (((p.x) > (ypos)) && ((p.x) < (ypos + 50)) && ((p.y) > (xpos)) && ((p.y) < (xpos + 150))) {
- DisplayScreen = 1;
- }
- ypos += 65;
- if (((p.x) > (ypos)) && ((p.x) < (ypos + 50)) && ((p.y) > (xpos)) && ((p.y) < (xpos + 150))) {
- DisplayScreen = 2;
- }
- ypos += 65;
- if (((p.x) > (ypos)) && ((p.x) < (ypos + 50)) && ((p.y) > (xpos)) && ((p.y) < (xpos + 150))) {
- DisplayScreen = 3;
- }
- xpos = 165;
- ypos = 10;
- if (((p.x) > (ypos)) && ((p.x) < (ypos + 50)) && ((p.y) > (xpos)) && ((p.y) < (xpos + 150))) {
- DisplayScreen = 3;
- }
- ypos += 65;
- if (((p.x) > (ypos)) && ((p.x) < (ypos + 50)) && ((p.y) > (xpos)) && ((p.y) < (xpos + 150))) {
- DisplayScreen = 1;
- }
- ypos += 65;
- if (((p.x) > (ypos)) && ((p.x) < (ypos + 50)) && ((p.y) > (xpos)) && ((p.y) < (xpos + 150))) {
- DisplayScreen = 1;
- }
- }
- //Startscherm met temperatuur en Toggle knoppen
- if (DisplayScreen == 1) {
- //Temp omhoog knop wordt aangeraakt
- if (((p.x) > (SetTempY)) && ((p.x) < (SetTempY + 100)) && ((p.y) > (SetTempX)) && ((p.y) < (SetTempX + 200))) {
- DisplayScreen = 2;
- }
- if (((p.x) > (Toggle1Y)) && ((p.x) < (Toggle1Y + 80)) && ((p.y) > (Toggle1X)) && ((p.y) < (Toggle1X + 80))) {
- SetToggle1();
- }
- if (((p.x) > (Toggle2Y)) && ((p.x) < (Toggle2Y + 80)) && ((p.y) > (Toggle2X)) && ((p.y) < (Toggle2X + 80))) {
- SetToggle2();
- }
- if (((p.x) > (MenuBtnY)) && ((p.x) < (MenuBtnY + 50)) && ((p.y) > (MenuBtnX)) && ((p.y) < (MenuBtnX + 50))) {
- DisplayScreen = 0;
- }
- }
- //Knoppen scherm 2
- else if (DisplayScreen == 2) {
- //Temp omhoog knop wordt aangeraakt
- if (((p.x) > (SetTemp2Y)) && ((p.x) < (SetTemp2Y + 100)) && ((p.y) > (SetTemp2X+20)) && ((p.y) < (SetTemp2X + 200))) {
- DisplayScreen = 1;
- }
- if (((p.x) > (UpBtnY)) && ((p.x) < (UpBtnY + 50)) && ((p.y) > (UpBtnX)) && ((p.y) < (UpBtnX + 50))) {
- TempUp();
- DrawSetTemp(SetTemp2X, SetTemp2Y);
- DrawHeatState(HeatStateX, HeatStateY);
- }
- //Temp omlaag knop wordt aangeraakt
- if (((p.x) > (DwnBtnY)) && ((p.x) < (DwnBtnY + 50)) && ((p.y) > (DwnBtnX)) && ((p.y) < (DwnBtnX + 50))) {
- TempDown();
- DrawSetTemp(SetTemp2X, SetTemp2Y);
- DrawHeatState(HeatStateX, HeatStateY);
- }
- }
- Serial.print("(");
- Serial.print(p.x);
- Serial.print(", ");
- Serial.print(p.y);
- Serial.println(")");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement