Components and supplies
1
Arduino Proto Shield
1
Arduino UNO
Tools and machines
1
Solder Wire, Lead Free
1
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
1
Soldering iron (generic)
1
10 Pc. Jumper Wire Kit, 5 cm Long
Project description
Code
circular gauge on ST7735
arduino
1 2 3 4#define cs 10 5#define dc 9 6#define rst 8 7#include <Adafruit_GFX.h> 8#include <Adafruit_ST7735.h> 9#include <SPI.h> 10#include "DHT.h" 11#define DHTPIN 2 12Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst); 13 14#define DHTTYPE DHT11 // DHT 11 15DHT dht(DHTPIN, DHTTYPE); 16 17#define BLACK 0x0000 18#define BLUE 0x001F 19#define RED 0xF800 20#define GREEN 0x07E0 21#define CYAN 0x07FF 22#define MAGENTA 0xF81F 23#define YELLOW 0xFFE0 24#define WHITE 0xFFFF 25#define GRAY 0xA514 26#define DARKRED 0x8800 27#define ORANGE 0xFC62 28 29float anglef = 0.0; 30float rayonf = 30.0; 31 32float anglefh = 0.0; 33float rayonfh = 30.0; 34 35int xo = 40; 36int yo = 48; 37 38int xo1 = 120; 39int yo1 = 48; 40 41float x1f = 0.0; 42float y1f = 0.0; 43int x1 = 0; 44int y1 = 0; 45 46float x1fh = 0.0; 47float y1fh = 0.0; 48int x1h = 0; 49int y1h = 0; 50 51float x2f = 0.0; 52float y2f = 0.0; 53int x2 = 0; 54int y2 = 0; 55 56float x2fh = 0.0; 57float y2fh = 0.0; 58int x2h = 0; 59int y2h = 0; 60 61float x1Bordf = 0.0; 62float y1Bordf = 0.0; 63int x1Bord = 0; 64int y1Bord = 0; 65 66float x1Bordfh = 0.0; 67float y1Bordfh = 0.0; 68int x1Bordh = 0; 69int y1Bordh = 0; 70 71float x2Bordf = 0.0; 72float y2Bordf = 0.0; 73int x2Bord = 0; 74int y2Bord = 0; 75 76float x2Bordfh = 0.0; 77float y2Bordfh = 0.0; 78int x2Bordh = 0; 79int y2Bordh = 0; 80 81 82int couleur = 0; 83 84int numeroBlocSeg = 0; 85int LastnumeroBlocSeg = 0; 86 87int numeroBlocSegHum = 0; 88int LastnumeroBlocSegHum = 0; 89 90float temperatureCourante = 0; 91float LasttemperatureCourante = -1; 92float MaxTemp = -1; 93float MinTemp = -1; 94 95float humiditeCourante = 0; 96float LasthumiditeCourante = -1; 97float MaxHum = -1; 98float MinHum = -1; 99 100void setup(){ 101 Serial.begin(9600); 102 103 tft.initR(INITR_REDTAB); 104 tft.setRotation(1); 105 tft.fillScreen(ST7735_BLACK); 106 tft.setCursor(1,1); 107 tft.setTextSize(2); 108 tft.setTextColor(ST7735_CYAN,ST7735_BLACK); 109 tft.print("initilisation"); 110 delay(200); 111 tft.fillScreen(ST7735_BLACK); 112 tft.setCursor(1,10); 113 tft.setTextSize(1); 114 tft.println(" DHT11 " ); 115 tft.println(""); 116 tft.setTextSize(1); 117 tft.println(" mesure Humidite "); 118 tft.println(""); 119 tft.println(""); 120 tft.print(" mesure temperature"); 121 tft.println(""); 122 tft.println(""); 123 tft.println(""); 124 tft.println(""); 125 tft.println(""); 126 tft.setTextColor(ST7735_CYAN,ST7735_BLACK); 127 128 delay(2000); 129 dht.begin(); 130 tft.fillScreen(ST7735_BLACK); 131 FonctionTraceJauge(); 132 FonctionTraceJauge2(); 133} 134 135void loop(){ 136 tft.setTextSize(1); 137 tft.setTextColor(ST7735_CYAN,ST7735_BLACK); 138 139 tft.setCursor(1,20); 140 tft.setTextSize(1); 141 142 float h = dht.readHumidity(); 143 temperatureCourante = dht.readTemperature(); 144 humiditeCourante = dht.readHumidity(); 145 if (isnan(temperatureCourante)) {return;} 146 147 static int CompteurRelevesTemperature = 0; 148 static float SommeRelevesTemperature = 0.0; 149 150 static int CompteurRelevesHumidite = 0; 151 static float SommeRelevesHumidite = 0.0; 152 153 CompteurRelevesTemperature++; 154 SommeRelevesTemperature = SommeRelevesTemperature + temperatureCourante; 155 156CompteurRelevesHumidite++; 157 SommeRelevesHumidite = SommeRelevesHumidite + humiditeCourante ; 158 tft.setCursor(112,4); 159 tft.setTextSize(1); 160 161 tft.print(int (h)); 162 tft.print(" %"); 163 164 165 166 numeroBlocSeg = int(h); 167 if (CompteurRelevesTemperature >= 50) 168 { 169 temperatureCourante = SommeRelevesTemperature / 50.0; 170 humiditeCourante = SommeRelevesHumidite / 50.0; 171 172 CompteurRelevesTemperature = 0; SommeRelevesTemperature = 0.0; 173 CompteurRelevesHumidite = 0; SommeRelevesHumidite = 0.0; 174 175 if (temperatureCourante > 38) {temperatureCourante = 38.0;} 176 else if (temperatureCourante < 0) {temperatureCourante = 0.0;} 177 178 if (humiditeCourante > 100) {temperatureCourante = 100.0;} 179 else if (humiditeCourante < 0) {humiditeCourante= 0.0;} 180 181 tft.setTextColor(GRAY, BLACK); 182 tft.setTextSize(1); 183 if (temperatureCourante >= 10) 184 { 185 tft.setCursor(35,4); tft.print(temperatureCourante, 0); 186 tft.setTextSize(1); tft.print((char)247); 187 } 188 else 189 { 190 tft.setCursor(35, 4); tft.print(temperatureCourante, 0); 191 tft.setTextSize(1); tft.print((char)247); 192 } 193 194 if (temperatureCourante > MaxTemp || MaxTemp == -1) {MaxTemp = temperatureCourante;} 195 if (temperatureCourante < MinTemp || MinTemp == -1) {MinTemp = temperatureCourante;} 196 197 if (humiditeCourante > MaxHum || MaxHum == -1) {MaxHum = humiditeCourante;} 198 if (humiditeCourante < MinHum || MinHum == -1) {MinHum = humiditeCourante;} 199 200 201 tft.setTextSize(1); 202 tft.setTextColor(BLUE, BLACK); 203 tft.setCursor(12, 102); tft.print(MinTemp, 0); tft.print((char)247); 204 tft.setTextColor(RED, BLACK); 205 tft.setCursor(50, 102); tft.print(MaxTemp, 0); tft.print((char)247); 206 207 tft.setTextSize(1); 208 tft.setTextColor(BLUE, BLACK); 209 tft.setCursor(96, 102); tft.print(MinHum, 0); tft.print(" %"); 210 tft.setTextColor(RED, BLACK); 211 tft.setCursor(130, 102); tft.print(MaxHum, 0); tft.print(" %"); 212 213 } 214 else {return;} 215 216 numeroBlocSeg = int(temperatureCourante); 217 218 if (temperatureCourante > LasttemperatureCourante) 219 { 220 for (int i = LastnumeroBlocSeg; i <= numeroBlocSeg; i++) 221 { 222 for (int j = 0; j <= 4; j++) 223 { 224 int AngleSegBloc = 263 - ((9 * i) + j); 225 226 anglef = float(AngleSegBloc); 227 anglef = anglef * 3.14159; 228 anglef = anglef / 180.0; 229 230 x1f = cos(anglef); 231 x1f = rayonf*x1f; 232 x1 = int(x1f); 233 234 y1f = sin(anglef); 235 y1f = rayonf*y1f; 236 y1 = int(y1f); 237 238 x2f = cos(anglef); 239 x2f = rayonf/1.5*x2f; 240 x2 = int(x2f); 241 242 y2f = sin(anglef); 243 y2f = rayonf/1.5*y2f; 244 y2 = int(y2f); 245 246 if (i >= 0 && i <= 7) {couleur = CYAN;} 247 else if (i >= 8 && i <= 18) {couleur = ORANGE;} 248 else if (i >= 19 && i <= 30) {couleur = GREEN;} 249 else if (i >= 31 && i <= 38) {couleur = RED;} 250 251 tft.drawLine(xo+x2, yo-y2, xo+x1, yo-y1, couleur); 252 } 253 } 254 255 LastnumeroBlocSeg = numeroBlocSeg; 256 LasttemperatureCourante = temperatureCourante; 257 } 258 else if (temperatureCourante < LasttemperatureCourante) 259 { 260 for (int i = LastnumeroBlocSeg; i >= numeroBlocSeg; i--) 261 { 262 for (int j = 0; j <= 4; j++) 263 { 264 int AngleSegBloc = 263 - ((9 * i) + j); 265 266 anglef = float(AngleSegBloc); 267 anglef = anglef * 3.14159; 268 anglef = anglef / 180.0; 269 270 x1f = cos(anglef); 271 x1f = rayonf*x1f; 272 x1 = int(x1f); 273 274 y1f = sin(anglef); 275 y1f = rayonf*y1f; 276 y1 = int(y1f); 277 278 x2f = cos(anglef); 279 x2f = rayonf/1.5*x2f; 280 x2 = int(x2f); 281 282 y2f = sin(anglef); 283 y2f = rayonf/1.5*y2f; 284 y2 = int(y2f); 285 286 tft.drawLine(xo+x2, yo-y2, xo+x1, yo-y1, BLACK); 287 } 288 } 289 290 LastnumeroBlocSeg = numeroBlocSeg; 291 LasttemperatureCourante = temperatureCourante; 292 293 294 } 295 296 numeroBlocSegHum = int(humiditeCourante)/2.4; 297 Serial.print(humiditeCourante); 298 if (humiditeCourante > LasthumiditeCourante) 299 { 300 for (int i = LastnumeroBlocSegHum; i <= numeroBlocSegHum; i++) 301 { 302 for (int j = 0; j <= 4; j++) 303 { 304 int AngleSegBloch = 263 - ((9 * i) + j); 305 306 anglefh = float(AngleSegBloch); 307 anglefh = anglefh * 3.14159; 308 anglefh = anglefh / 180.0; 309 310 x1fh = cos(anglefh); 311 x1fh = rayonfh*x1fh; 312 x1h = int(x1fh); 313 314 y1fh = sin(anglefh); 315 y1fh = rayonfh*y1fh; 316 y1h = int(y1fh); 317 318 x2fh = cos(anglefh); 319 x2fh = rayonfh/1.5*x2fh; 320 x2h = int(x2fh); 321 322 y2fh = sin(anglefh); 323 y2fh = rayonfh/1.5*y2fh; 324 y2h = int(y2fh); 325 326 if (i >= 0 && i <= 7) {couleur = CYAN;} 327 else if (i >= 8 && i <= 18) {couleur = ORANGE;} 328 else if (i >= 19 && i <= 30) {couleur = GREEN;} 329 else if (i >= 31 && i <= 38) {couleur = RED;} 330 331 tft.drawLine(xo1+x2h, yo1-y2h, xo1+x1h, yo1-y1h, couleur); 332 } 333 } 334 335 LastnumeroBlocSegHum = numeroBlocSegHum; 336 LasthumiditeCourante = humiditeCourante; 337 } 338 else if (humiditeCourante < LasthumiditeCourante) 339 { 340 for (int i = LastnumeroBlocSegHum; i >= numeroBlocSegHum; i--) 341 { 342 for (int j = 0; j <= 4; j++) 343 { 344 int AngleSegBloch = 263 - ((9 * i) + j); 345 346 anglefh = float(AngleSegBloch); 347 anglefh = anglefh * 3.14159; 348 anglefh = anglefh / 180.0; 349 350 x1fh = cos(anglefh); 351 x1fh = rayonfh*x1fh; 352 x1h = int(x1fh); 353 354 y1fh = sin(anglefh); 355 y1fh = rayonfh*y1fh; 356 y1h = int(y1fh); 357 358 x2fh = cos(anglefh); 359 x2fh = rayonfh/1.5*x2fh; 360 x2h = int(x2fh); 361 362 y2fh = sin(anglefh); 363 y2fh = rayonfh/1.5*y2fh; 364 y2h = int(y2fh); 365 366 tft.drawLine(xo1+x2h, yo1-y2h, xo1+x1h, yo1-y1h, BLACK); 367 } 368 369 } 370 LastnumeroBlocSegHum = numeroBlocSegHum; 371 LasthumiditeCourante = humiditeCourante; 372 373 374 } 375} 376 377 void FonctionTraceJauge () 378{ 379 for (int i = 266; i >= -86; i--) 380 { 381 anglef = float(i); 382 anglef = anglef * 3.14159; 383 anglef = anglef / 180.0; 384 385 x1Bordf = cos(anglef); 386 x1Bordf = rayonf*1.04*x1Bordf; 387 x1Bord = int(x1Bordf); 388 389 y1Bordf = sin(anglef); 390 y1Bordf = rayonf*1.04*y1Bordf; 391 y1Bord = int(y1Bordf); 392 393 x2Bordf = cos(anglef); 394 x2Bordf = rayonf/1.6*x2Bordf; 395 x2Bord = int(x2Bordf); 396 397 y2Bordf = sin(anglef); 398 y2Bordf = rayonf/1.6*y2Bordf; 399 y2Bord = int(y2Bordf); 400 401 if (i == 266 || i == -86) {tft.drawLine(xo+x2Bord, yo-y2Bord, xo+x1Bord, yo-y1Bord, BLUE);} 402 tft.drawPixel(xo+x2Bord, yo-y2Bord, BLUE); 403 tft.drawPixel(xo+x1Bord, yo-y1Bord, BLUE); 404 } 405 406 for (int i = 0; i <= 38; i++) 407 { 408 int AngleSegBloc = 263 - ((9 * i)); 409 410 anglef = float(AngleSegBloc); 411 anglef = anglef * 3.14159; 412 anglef = anglef / 180.0; 413 414 x1f = cos(anglef); 415 x1f = rayonf*x1f; 416 x1 = int(x1f); 417 418 y1f = sin(anglef); 419 y1f = rayonf*y1f; 420 y1 = int(y1f); 421 422 x2f = cos(anglef); 423 x2f = rayonf*1.1*x2f; 424 x2 = int(x2f); 425 426 y2f = sin(anglef); 427 y2f = rayonf*1.1*y2f; 428 y2 = int(y2f); 429 if (i >= 0 && i <= 7) {couleur = CYAN;} 430 else if (i >= 8 && i <= 18) {couleur = YELLOW;} 431 else if (i >= 19 && i <= 30) {couleur = ORANGE;} 432 else if (i >= 31 && i <= 38) {couleur = RED;} 433 434 if (i % 2 == 0) {tft.drawLine(xo+x2, yo-y2, xo+x1, yo-y1, couleur);} 435 } 436 437 438 439 tft.setTextColor(WHITE, BLACK); 440 441 442 tft.fillCircle(xo, yo, 13, CYAN); 443 tft.fillCircle(xo, yo, 6, RED); 444 445 tft.setTextColor(GRAY, BLACK); 446 tft.setTextSize(1); 447 tft.setCursor(15, 86); tft.print(F("TMin")); 448 tft.setCursor(50, 86); tft.print(F("TMax")); 449 450 451 452} 453 454 void FonctionTraceJauge2 () 455{ 456 for (int i = 266; i >= -86; i--) 457 { 458 anglef = float(i); 459 anglef = anglef * 3.14159; 460 anglef = anglef / 180.0; 461 462 x1Bordf = cos(anglef); 463 x1Bordf = rayonf*1.04*x1Bordf; 464 x1Bord = int(x1Bordf); 465 466 y1Bordf = sin(anglef); 467 y1Bordf = rayonf*1.04*y1Bordf; 468 y1Bord = int(y1Bordf); 469 470 x2Bordf = cos(anglef); 471 x2Bordf = rayonf/1.6*x2Bordf; 472 x2Bord = int(x2Bordf); 473 474 y2Bordf = sin(anglef); 475 y2Bordf = rayonf/1.6*y2Bordf; 476 y2Bord = int(y2Bordf); 477 478 if (i == 266 || i == -86) {tft.drawLine(xo1+x2Bord, yo1-y2Bord, xo1+x1Bord, yo1-y1Bord, BLUE);} 479 tft.drawPixel(xo1+x2Bord, yo1-y2Bord, BLUE); 480 tft.drawPixel(xo1+x1Bord, yo1-y1Bord, BLUE); 481 } 482 483 for (int i = 0; i <= 38; i++) 484 { 485 int AngleSegBloc = 263 - ((9 * i)); 486 487 anglef = float(AngleSegBloc); 488 anglef = anglef * 3.14159; 489 anglef = anglef / 180.0; 490 491 x1f = cos(anglef); 492 x1f = rayonf*x1f; 493 x1 = int(x1f); 494 495 y1f = sin(anglef); 496 y1f = rayonf*y1f; 497 y1 = int(y1f); 498 499 x2f = cos(anglef); 500 x2f = rayonf*1.1*x2f; 501 x2 = int(x2f); 502 503 y2f = sin(anglef); 504 y2f = rayonf*1.1*y2f; 505 y2 = int(y2f); 506 507 if (i >= 0 && i <= 7) {couleur = CYAN;} 508 else if (i >= 8 && i <= 18) {couleur = YELLOW;} 509 else if (i >= 19 && i <= 30) {couleur = ORANGE;} 510 else if (i >= 31 && i <= 38) {couleur = RED;} 511 512 if (i % 2 == 0) {tft.drawLine(xo1+x2, yo1-y2, xo1+x1, yo1-y1, couleur);} 513 } 514 515 516 517 tft.setTextColor(WHITE, BLACK); 518 519 520 tft.fillCircle(xo1, yo1, 13, CYAN); 521 tft.fillCircle(xo1, yo1, 6, RED); 522 523 tft.setTextColor(GRAY, BLACK); 524 tft.setTextSize(1); 525 tft.setCursor(95, 86); tft.print(F("HMin")); 526 tft.setCursor(135, 86); tft.print(F("HMax")); 527} 528
Downloadable files
wiring DHT 11
wiring DHT 11

wiring DHT 11
wiring DHT 11

Comments
Only logged in users can leave comments