1 | #include <TFT.h> // Hardware-specific library
|
2 | #include <SPI.h>
|
3 |
|
4 | #define CS 7
|
5 | #define DC 0
|
6 | #define RESET 1
|
7 |
|
8 | TFT myScreen = TFT(CS, DC, RESET);
|
9 | int Start=1;
|
10 | int StartAus=1;
|
11 | int Aus=1;
|
12 | int Ein=1;
|
13 | int StartEin=0;
|
14 | int Messen=0;
|
15 | int MessStart=1;
|
16 | int a=25;
|
17 | int e=30;
|
18 | int sensorValue;
|
19 | int altValue;
|
20 | char printout[4];
|
21 | unsigned long previousMillis = 0;
|
22 | unsigned long interval = 22000;
|
23 |
|
24 | void setup(){
|
25 | Serial.begin(9600);
|
26 | pinMode(A1, INPUT_PULLUP);
|
27 | pinMode(12, INPUT);
|
28 | pinMode(4, INPUT);
|
29 | pinMode(2, INPUT_PULLUP);
|
30 | pinMode(10, OUTPUT);
|
31 | pinMode(LED_BUILTIN, OUTPUT);
|
32 | myScreen.begin();
|
33 | myScreen.background(0,255,125); // clear the screen
|
34 | myScreen.noStroke(); // don't draw a line around the next rectangle
|
35 | myScreen.fill(235,255,245); // set the fill color to green
|
36 | myScreen.rect(28,23,myScreen.width(),50);
|
37 | myScreen.setTextSize(3);
|
38 | myScreen.stroke(30,255,255);
|
39 | myScreen.text("Hallo",30,25);
|
40 | myScreen.stroke(0,255,25);
|
41 | myScreen.text("Welt",30,50);
|
42 | delay(250) ;
|
43 | myScreen.setTextSize(1);
|
44 | myScreen.stroke(255,0,55);
|
45 | myScreen.text("loading",60,100);
|
46 | delay(125) ;
|
47 | myScreen.noStroke(); // don't draw a line around the next rectangle
|
48 | myScreen.fill(255,0,55); // set the fill color to green
|
49 | myScreen.rect(140,110,myScreen.width(),3);
|
50 | delay(125);
|
51 | myScreen.noStroke(); // don't draw a line around the next rectangle
|
52 | myScreen.fill(255,0,55); // set the fill color to green
|
53 | myScreen.rect(120,110,myScreen.width(),3);
|
54 | delay(125);
|
55 | myScreen.noStroke(); // don't draw a line around the next rectangle
|
56 | myScreen.fill(255,0,55); // set the fill color to green
|
57 | myScreen.rect(90,110,myScreen.width(),3);
|
58 | delay(250);
|
59 | myScreen.noStroke(); // don't draw a line around the next rectangle
|
60 | myScreen.fill(255,0,55); // set the fill color to green
|
61 | myScreen.rect(80,110,myScreen.width(),3);
|
62 | delay(250);
|
63 | myScreen.noStroke(); // don't draw a line around the next rectangle
|
64 | myScreen.fill(255,0,55); // set the fill color to green
|
65 | myScreen.rect(50,110,myScreen.width(),3);
|
66 | delay(125);
|
67 | myScreen.noStroke(); // don't draw a line around the next rectangle
|
68 | myScreen.fill(255,0,55); // set the fill color to green
|
69 | myScreen.rect(30,110,myScreen.width(),3);
|
70 | delay(250);
|
71 | myScreen.noStroke(); // don't draw a line around the next rectangle
|
72 | myScreen.fill(255,0,55); // set the fill color to green
|
73 | myScreen.rect(10,110,myScreen.width(),3);
|
74 | delay(250);
|
75 | myScreen.noStroke(); // don't draw a line around the next rectangle
|
76 | myScreen.fill(255,0,55); // set the fill color to green
|
77 | myScreen.rect(0,110,myScreen.width(),3);
|
78 | delay(500);
|
79 | }
|
80 | void loop(){
|
81 |
|
82 | if(Start==1){
|
83 |
|
84 | if(StartAus==1){
|
85 | myScreen.background(0,255,125);
|
86 | myScreen.stroke(255,0,255);
|
87 | myScreen.setTextSize(2);
|
88 | myScreen.text("Ausschalt",0,1);
|
89 | myScreen.text("Temperatur:",0,20);
|
90 | myScreen.stroke(50,0,255);
|
91 | myScreen.text("Grad",80,66);
|
92 | StartAus=0;
|
93 | }
|
94 | if((digitalRead(2)==HIGH)&&(Aus==1)){
|
95 | myScreen.setTextSize(5);
|
96 | myScreen.stroke(0,255,125);
|
97 | myScreen.text(printout,0,45);
|
98 | String myString = String(a);
|
99 | myString.toCharArray(printout,4);
|
100 | myScreen.stroke(50,0,255);
|
101 | myScreen.text(printout,0,45);
|
102 | delay(100);
|
103 |
|
104 | if(digitalRead(4)==LOW){
|
105 | a++;
|
106 | Serial.println(a);
|
107 |
|
108 | }
|
109 | if(digitalRead(12)==LOW){
|
110 | a--;
|
111 | Serial.println(a);
|
112 |
|
113 |
|
114 | }
|
115 | }
|
116 | if((digitalRead(2)==LOW)&&(Ein==1)){
|
117 | Aus=0;
|
118 | myScreen.background(0,255,125);
|
119 | myScreen.stroke(255,0,255);
|
120 | myScreen.setTextSize(2);
|
121 | myScreen.text("Einschalt",0,1);
|
122 | myScreen.text("Temperatur:",0,20);
|
123 | myScreen.stroke(50,0,255);
|
124 | myScreen.text("Grad",80,66);
|
125 | Ein=0;
|
126 | StartEin=1;
|
127 | }
|
128 | if(StartEin==1){
|
129 | myScreen.setTextSize(5);
|
130 | myScreen.stroke(0,255,125);
|
131 | myScreen.text(printout,0,45);
|
132 | String myString = String(e);
|
133 | myString.toCharArray(printout,4);
|
134 | myScreen.stroke(50,0,255);
|
135 | myScreen.text(printout,0,45);
|
136 | delay(100);
|
137 |
|
138 | if(digitalRead(4)==LOW){
|
139 | e++;
|
140 | Serial.println(e);
|
141 |
|
142 | }
|
143 | if(digitalRead(12)==LOW){
|
144 | e--;
|
145 | Serial.println(e);
|
146 |
|
147 |
|
148 | }
|
149 | }
|
150 | if (millis() - previousMillis > interval) {
|
151 | previousMillis = millis();
|
152 | Start=0;
|
153 | Messen=1;
|
154 | }
|
155 | }
|
156 | if(Messen==1){
|
157 |
|
158 | if(MessStart==1){
|
159 | myScreen.background(0,255,125);
|
160 | myScreen.setTextSize(2);
|
161 | myScreen.stroke(255,0,255);
|
162 | myScreen.text("Aktuelle ",0,1);
|
163 | myScreen.text("Temperatur:",0,20);
|
164 | myScreen.stroke(50,0,255);
|
165 | myScreen.text("Grad",80,66);
|
166 | MessStart=0;
|
167 |
|
168 | }
|
169 | myScreen.setTextSize(5);
|
170 | int reading = analogRead(A1);
|
171 | float voltage = reading * 5.0;
|
172 | voltage /= 1024.0;
|
173 | Serial.print(voltage);
|
174 | Serial.println(" volts");
|
175 | float temperature = (voltage - 0.5) * 100 ;
|
176 | Serial.print(temperature); Serial.println(" degrees C");
|
177 | sensorValue = int(temperature);
|
178 | sensorValue = map(analogRead(A1), 0,500 , 450,0 );
|
179 | sensorValue= sensorValue/10;
|
180 | String myString2 = String(sensorValue);
|
181 | myString2.toCharArray(printout,6);
|
182 | if (sensorValue != altValue){
|
183 | myScreen.noStroke(); // don't draw a line around the next rectangle
|
184 | myScreen.fill(0,255,125); // set the fill color to green
|
185 | myScreen.rect(0,45,myScreen.width(),35);
|
186 | myScreen.stroke(50,0,255);
|
187 | myScreen.text(printout,0,45);
|
188 | myScreen.setTextSize(2);
|
189 | myScreen.text("Grad",80,66);
|
190 | delay(500);
|
191 |
|
192 | }
|
193 | altValue=sensorValue;
|
194 | if(sensorValue>=e){
|
195 | Serial.println(" Ein");
|
196 | digitalWrite(LED_BUILTIN, HIGH);
|
197 | delay(1000);
|
198 |
|
199 | }
|
200 | if(sensorValue<=a){
|
201 | Serial.println("Aus");
|
202 | digitalWrite(LED_BUILTIN, LOW);
|
203 | delay(1000);
|
204 | }
|
205 | }
|
206 |
|
207 | }
|