{\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf200 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} {\*\expandedcolortbl;;} \paperw11900\paperh16840\margl1440\margr1440\vieww14560\viewh23580\viewkind0 \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0 \f0\fs24 \cf0 //Library f\'fcr Display (inkl. Touch)\ #include // Core graphics library\ #include // Hardware-specific library\ #include \ \ #if defined(__SAM3X8E__)\ #undef __FlashStringHelper::F(string_literal)\ #define F(string_literal) string_literal\ #endif\ \ //Library f\'fcr Uhrzeit (Timer)\ #include "TimerOne.h"\ \ //Library f\'fcr Temperatursensor\ #include \ #include \ \ // Pin Temperatursensor\ #define ONE_WIRE_BUS 2\ //////////////////////////////////////////////////////////////////////////////////////\ // F\'fcr Display\ //\ #define YP A3\ #define XM A2 \ #define YM 9 \ #define XP 8 \ \ //Touch\ #define TS_MINX 120\ #define TS_MAXX 900\ \ #define TS_MINY 70\ #define TS_MAXY 920\ \ TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);\ \ #define LCD_CS A3\ #define LCD_CD A2\ #define LCD_WR A1\ #define LCD_RD A0\ // optional\ #define LCD_RESET A4\ \ #define BLACK 0x0000\ #define BLUE 0x001F\ #define RED 0xF800\ #define GREEN 0x07E0\ #define CYAN 0x07FF\ #define MAGENTA 0xF81F\ #define YELLOW 0xFFE0\ #define WHITE 0xFFFF\ #define GRAY 0xDEFB\ \ Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);\ \ #define PENRADIUS 2\ \ OneWire oneWire(ONE_WIRE_BUS);\ DallasTemperature sensors(&oneWire);\ \ int screen_id = 0;\ int stunde = 0;\ int minute = 0;\ int sekunde = 0;\ float TempMin = 0;\ float TempMax = 0; \ \ void Uhrzeit()\ \{\ //Uhrzeit\ tft.setTextColor(WHITE, BLACK); //Schriftart mit Texthintergrund\ tft.setCursor(10,10); //Position\ tft.setTextSize(2); //Text gr\'f6\'dfe\ tft.println("Uhrzeit");\ tft.setTextSize(3); //Text gr\'f6\'dfe\ tft.setCursor(50,50);\ if (stunde < 10) tft.print("0");\ tft.print(stunde);\ tft.print(":");\ if (minute < 10) tft.print("0");\ tft.print(minute);\ tft.print(":");\ if (sekunde < 10) tft.print("0");\ tft.print(sekunde);\ //tft.println(" Uhr");\ \}\ \ void Temperatur()\ \{\ //Temperatur\ sensors.requestTemperatures();\ \ tft.setCursor(10,140); //Position\ tft.setTextSize(2); //Text gr\'f6\'dfe\ tft.println("Raumtemperatur");\ tft.setTextSize(3); //Text gr\'f6\'dfe\ tft.setCursor(80,180);\ tft.print(sensors.getTempCByIndex(0));\ tft.print(" ");\ tft.print(char(247)); //Symbol: \'b0\ tft.println("C"); \ \ //Tageswerte Min / Max\ if (stunde == 0 && minute == 0 && sekunde == 0)\ \{\ TempMax = sensors.getTempCByIndex(0);\ TempMin = sensors.getTempCByIndex(0);\ \}\ else\ \{\ if (TempMax < sensors.getTempCByIndex(0)) TempMax = sensors.getTempCByIndex(0);\ if (TempMin > sensors.getTempCByIndex(0)) TempMin = sensors.getTempCByIndex(0);\ \}\ \ tft.setCursor(40,250); //Position\ tft.setTextColor(RED, BLACK); //Schriftart mit Texthintergrund\ tft.setTextSize(2); //Text gr\'f6\'dfe\ tft.println("Max");\ \ tft.setCursor(160,250); //Position\ tft.setTextColor(BLUE, BLACK); //Schriftart mit Texthintergrund\ tft.setTextSize(2); //Text gr\'f6\'dfe\ tft.println("Min");\ \ tft.setTextColor(WHITE, BLACK); //Schriftart mit Texthintergrund\ tft.setCursor(30,280); //Position\ tft.print(TempMax);\ tft.print(char(247)); //Symbol: \'b0\ tft.println("C"); \ \ tft.setCursor(150,280); //Position\ tft.print(TempMin);\ tft.print(char(247)); //Symbol: \'b0\ tft.println("C"); \ \}\ \ //////////////////////////////////////////////////////////////////////////////////////\ // Zeit zeigen \ // \ void Zeit()\ \{ \ sekunde++;\ \ if (sekunde == 60)\ \{\ minute++;\ sekunde = 0;\ \ if (minute > 59)\ \{\ stunde++;\ minute = 0;\ \}\ \ if (stunde > 23)\ \{\ stunde = 0;\ \}\ \}\ \}\ \ void setup()\ \{\ //////////////////////////////////////////////////////////////////////////////////////\ // Interrupt\ // \ Timer1.initialize(1*1000000); //jede sekunde Interrupt aufrufen\ Timer1.attachInterrupt(Zeit);\ //////////////////////////////////////////////////////////////////////////////////////\ // Sensor\ // \ sensors.begin();\ //////////////////////////////////////////////////////////////////////////////////////\ // Display Einstellungen\ //\ Serial.begin(9600);\ tft.reset();\ \ uint16_t identifier = tft.readID();\ if (identifier == 0x9325) \{\ Serial.println(F("Found ILI9325 LCD driver"));\ \} else if (identifier == 0x9328) \{\ Serial.println(F("Found ILI9328 LCD driver"));\ \} else if (identifier == 0x4535) \{\ Serial.println(F("Found LGDP4535 LCD driver"));\ \} else if (identifier == 0x7575) \{\ Serial.println(F("Found HX8347G LCD driver"));\ \} else if (identifier == 0x9341) \{\ Serial.println(F("Found ILI9341 LCD driver"));\ \} else if (identifier == 0x8357) \{\ Serial.println(F("Found HX8357D LCD driver"));\ \} else if (identifier == 0x0101)\ \{\ identifier = 0x9341;\ Serial.println(F("Found 0x9341 LCD driver"));\ \} else \{\ identifier = 0x9341;\ \}\ \ tft.begin(identifier);\ tft.fillScreen(BLACK);\ \ tft.setRotation(2); //Ausrichtung Schrift\ tft.setTextColor(WHITE, BLACK); //Schriftart mit Texthintergrund\ tft.drawRect(2,2,235,315,WHITE); //Rechteck, Abstand x, Abstadn y, breite, h\'f6he\ tft.drawLine(2,130,235,130,WHITE); //Line unter Uhrzeit\ tft.drawLine(2,230,235,230,WHITE); //Line unter Temperatur\ //Minute + 1\ tft.fillRect(70,90,40,35, BLUE);\ tft.drawRect(70,90,40,35,WHITE);\ tft.setCursor(83,97);\ tft.setTextColor(WHITE);\ tft.setTextSize(3);\ tft.print("+");\ //Minute - 1\ tft.fillRect(120,90,40,35, BLUE);\ tft.drawRect(120,90,40,35,WHITE);\ tft.setCursor(133,97);\ tft.setTextColor(WHITE);\ tft.setTextSize(3);\ tft.print("-");\ \ TempMax = sensors.getTempCByIndex(0);\ TempMin = sensors.getTempCByIndex(0);\ \}\ \ #define MINPRESSURE 10\ #define MAXPRESSURE 1000\ \ void loop()\ \{\ touch(); \ Uhrzeit();\ Temperatur();\ \}\ \ void touch()\ \{\ // Touchscreen\ TSPoint p = ts.getPoint();\ pinMode(XM, OUTPUT);\ pinMode(YP, OUTPUT);\ \ if (p.z > MINPRESSURE && p.z < MAXPRESSURE) \ \{\ p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);\ p.y = (tft.height() - map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));\ \ Serial.print("("); Serial.print(p.x);\ Serial.print(", "); Serial.print(p.y);\ Serial.println(")");\ \ if (p.x > 70 && p.x < 110 && p.y > 90 && p.y < 125) // Button f\'fcr "+"\ \{\ if (minute < 59)\ \{\ minute = minute + 1;\ \}\ else\ \{\ minute = 0;\ if (stunde < 23)\ \{\ stunde = stunde +1;\ \}\ else\ \{\ stunde = 0;\ \}\ \}\ sekunde = 0;\ \}\ \ if (p.x > 120 && p.y < 160 && p.y > 90 && p.y < 125) // Button f\'fcr "-"\ \{\ if (minute > 0)\ \{\ minute = minute - 1;\ \}\ else\ \{\ minute = 59;\ if (stunde > 0)\ \{\ stunde = stunde -1;\ \}\ else \ \{\ stunde = 23;\ \}\ \}\ sekunde = 0;\ \}\ \} \ \}\ }