Components and supplies
10 LEDs Bar Array, Green
Arduino UNO
FPGA Configuration Memory, EEPROM
Grove - I2C High Accuracy Temp&Humi Sensor (SHT35)
TFT Touchscreen, 320x240
Resistor 220 ohm
Toggle Switch, (On)-Off-(On)
MyOctopus i2c Barometric Air Pressure Sensor BMP280
Shift Register- Serial to Parallel
Tools and machines
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
Code
Barometer
arduino
Barometer/thermometer/humiditymeter
1//************************************************************************** 2#include <Adafruit_BMP085.h> 3#include "SHT31.h" 4#include <SPI.h> 5#include <Wire.h> 6#include <AT24CX.h> // eeprom 256kbit 7#include <Adafruit_GFX.h> // Include core graphics library 8#include <Adafruit_ILI9341.h> // Include Adafruit_ILI9341 library to drive the display 9//#define TFT_DC 10 10//#define TFT_RST 9 11//#define TFT_CS 8 12Adafruit_ILI9341 tft = Adafruit_ILI9341(8, 10, 9); 13#define I2C_ADDRESS 0x77 14#define SHT31_ADDRESS 0x44 15#define BLACK 0x0000 16#define BLUE 0x001F 17#define RED 0xF800 18#define GREEN 0x07E0 19#define YELLOW 0xFFE0 20#define WHITE 0xFFFF 21Adafruit_BMP085 bmp; 22AT24CX mem; 23SHT31 sht; 24byte dataPin = 2; 25byte latchPin = 3; 26byte clockPin = 4; 27byte TFTL = 7; 28byte LedRange = 6;// schaalverlichting 29byte SW1 = A0; 30byte SW2 = A1; 31byte SW3 = A2; 32byte SW4 = A3; 33byte LB; 34byte HB; 35int BR; 36int TM; 37int HG; 38byte uur; 39byte minuut; 40byte seconde; 41byte xy[192]; 42byte testH; 43byte testL; 44float Temp; 45float Temp1; 46float Hygro; 47float Hygro1; 48float Baro; 49byte test1; 50byte test2; 51byte test3; 52byte test4; 53byte ddd[17]; 54unsigned long currentMillis; 55long interval = 30000; 56long previousMillis = 0; 57unsigned long BcurrentMillis; 58long Binterval = 900000; 59long BpreviousMillis = 0; 60unsigned long TijdcurrentMillis; 61long Tijdinterval = 86400000; 62long TijdpreviousMillis = 0; 63byte rij1[11] = { 0, 2, 4, 8, 16, 32, 0, 0, 0, 0, 0}; // dotmode 64byte rij2[11] = { 32, 0, 0, 0, 0, 0, 2, 4, 8, 16, 0}; // dotmode 65byte kolom1BM[12] = { 253, 251, 247, 239, 223, 255, 255, 255, 255, 255, 255, 255}; // dot en barmode 66byte kolom2BM[12] = { 255, 255, 255, 255, 255, 253, 251, 247, 239, 223, 223, 255}; // dot en barmode 67byte rij1BM[11] = { 62, 2, 6, 14, 30, 62, 62, 62, 62, 62, 0}; // barmode 68byte rij2BM[11] = { 62, 0, 0, 0, 0, 0, 2, 6, 14, 30, 0}; // barmode 69//--------------------------------------------------------------------- 70void setup() { 71 pinMode(latchPin, OUTPUT); 72 pinMode(clockPin, OUTPUT); 73 pinMode(dataPin, OUTPUT); 74 pinMode(TFTL, OUTPUT); 75 pinMode(LedRange, OUTPUT); 76 pinMode(SW1, INPUT_PULLUP); 77 pinMode(SW2, INPUT_PULLUP); 78 pinMode(SW3, INPUT_PULLUP); 79 pinMode(SW4, INPUT_PULLUP); 80 digitalWrite(TFTL, HIGH); 81 82 Serial.begin(9600); 83 Wire.begin(); 84 sht.begin(SHT31_ADDRESS); 85 86 if (!bmp.begin(I2C_ADDRESS)) { 87 //Serial.println("Could not find a valid BMP085 sensor, check wiring!"); 88 while (1) {} 89 } 90 delay (1000); 91 SensorLDUitlezen(); 92 tft.begin(); // Initialize display 93 94 tft.fillScreen(BLACK); // Fill screen with black 95 96 tft.setRotation(1); // Set orientation of the display. Values are from 0 to 3. If not declared, orientation would be 0, 97 // which is portrait mode. 98 99 tft.setTextWrap(false); // By default, long lines of text are set to automatically wrap back to the leftmost column. 100 // To override this behavior (so text will run off the right side of the display - useful for 101 // scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored 102 // with setTextWrap(true). 103 tft.setTextSize(3); // Set text size. Goes from 0 (the smallest) to 20 (very big) 104 105 // tft.backlight(off); 106 BarCode(0, 10, 11); 107 digitalWrite(LedRange, LOW); 108 Bartest(); 109 delay(1000); 110 float2byte (1200, 100, 0); 111 float2byte (1202, 0, 0); 112 float2byte (2200, 100, 0); 113 float2byte (2202, 0, 0); 114 115 /* 116 for (int x = 2000 ; x < 2188; x += 2) { 117 mem.write(x, 50); 118 mem.write(x + 1, 0); 119 } 120 for (int x = 1000 ; x < 1188; x += 2) { 121 mem.write(x, 20); 122 mem.write(x + 1, 0); 123 } 124 for (int x = 0 ; x < 188; x += 2) { 125 mem.write(x, 50); 126 mem.write(x + 1, 0); 127 } 128 */ 129 130 131 //float2byte(200, 972.84, 950); 132 133 134 //float2byte(202, 1025.46, 950); 135 136 137 138} 139 140//--------------------------------------------------------------------------------- 141void loop() { 142 143 byte test; 144 test1 = digitalRead(SW1); 145 test2 = digitalRead(SW2); 146 test3 = digitalRead(SW3); 147 test4 = digitalRead(SW4); 148 test = test4 * 8; 149 test += test3 * 4; 150 test += test2 * 2; 151 test += test1; 152 153 154 switch (test) { 155 case 0 : //0000 156 if (ddd[0] == 0) 157 { 158 dddInstellen(0); 159 tft.begin(); 160 digitalWrite(TFTL, LOW); 161 digitalWrite(LedRange, LOW); 162 tft.fillScreen(BLACK); 163 tft.setRotation(1); 164 tft.setTextWrap(false); 165 BarCode(0, 10, 11); // led array uit 166 167 } 168 break; 169 //================================ 170 171 case 1 : //0001 172 if (ddd[1] == 0) 173 { 174 dddInstellen(1); 175 CHBtekst(); 176 } 177 break; 178 //================================ 179 case 2 : // 0010 barmode 180 if (ddd[2] == 0) 181 { 182 dddInstellen(2); 183 Sensortekst(950, Baro, 1050, "Sch.: 10 mBar ", GREEN); 184 } 185 SensorW( Baro, 950, 1); 186 // bereik = 950 - 1050 mB 187 // 1 led = 1 mB 188 break; 189 //============================= 190 case 3 : // 0011 barmode 191 if (ddd[3] == 0) 192 { 193 dddInstellen(3); 194 Sensortekst(0, Temp, 50, "Sch.: 5 gr. C ", RED); 195 } 196 SensorW( Temp, 0, 2); 197 198 // bereik = 0 - 50 C 199 // 5 graad = 10 led 200 break; 201 //====================================== 202 case 4 : // 0100 barmode 203 if (ddd[4] == 0) 204 { 205 dddInstellen(4); 206 Sensortekst(0, Hygro, 100, "Sch.: 10 % ", BLUE); 207 } 208 SensorW( Hygro, 0, 1); 209 210 // bereik = 0 - 100 % 211 break; 212 //=================================== 213 case 5 : // 0101 trend past 24 hours 214 if (ddd[5] == 0) 215 { 216 dddInstellen(5); 217 String Tekst; 218 Tekst = Baro; 219 Tekst = "Baro = " + Tekst; 220 Grafiek(0, 188, 950, Tekst, "x"); //startadres,stopadres, waardeverekening baro 221 } 222 SensorW( Baro, 950, 1); 223 break; 224 //========================== 225 case 6 : // 0110 trend past 24 hours 226 if (ddd[6] == 0) 227 { 228 dddInstellen(6); 229 String Tekst; 230 Tekst = Temp; 231 Tekst = "Temp = " + Tekst; 232 Grafiek(1000, 1188, 0, Tekst, "x"); //startadres,stopadres, waardeverekening temp 233 } 234 SensorW( Temp, 0, 2); 235 break; 236 //================================== 237 case 7 : // 0111 trend past 24 hours 238 if (ddd[7] == 0) 239 { 240 dddInstellen(7); 241 String Tekst; 242 Tekst = Hygro; 243 Tekst = "Hygro = " + Tekst; 244 Grafiek(2000, 2188, 0, Tekst, "x"); //startadres,stopadres, waardeverekening hygro 245 } 246 SensorW( Hygro, 0, 1); 247 break; 248 //================================== 249 case 8 : // 1000 airpressure trend 250 if (ddd[8] == 0) 251 { 252 BarCode(0, 10, 11); 253 digitalWrite(LedRange, LOW); 254 dddInstellen(8); 255 WeerTrend(); 256 } 257 break; 258 //=================================== 259 case 9 : // 1001 max min temperature 260 if (ddd[9] == 0) 261 { 262 BarCode(0, 10, 11); 263 digitalWrite(LedRange, LOW); 264 dddInstellen(9); 265 THData(); 266 } 267 break; 268 //================================== 269 case 10 : // 1010 dotmode 270 if (ddd[10] == 0) 271 { 272 dddInstellen(10); 273 Sensortekst(950, Baro, 1050, "Sch.: 10 mBar ", GREEN); 274 } 275 SensorD( Baro, 950, 1); 276 // bereik = 950 - 1050 mB 277 // 1 led = 1 mB 278 break; 279 280 //============================= 281 case 11 : // 1011 dotmode 282 if (ddd[11] == 0) 283 { 284 dddInstellen(11); 285 Sensortekst(0, Temp, 50, "Sch.: 5 gr. C ", RED); 286 } 287 SensorD( Temp, 0, 2); 288 289 // bereik = 0 - 50 C 290 // 5 graad = 10 led 291 break; 292 //====================================== 293 case 12 : // 1100 dotmode 294 if (ddd[12] == 0) 295 { 296 dddInstellen(12); 297 Sensortekst(0, Hygro, 100, "Sch.: 10 % ", BLUE); 298 } 299 SensorD( Hygro, 0, 1); 300 301 // bereik = 0 - 100 % 302 break; 303 //=================================== 304 case 13 : // 1101 zoommode x 10 305 if (ddd[13] == 0) 306 307 { 308 dddInstellen(13); 309 //String Tekst; 310 //Tekst = Baro; 311 //Tekst = "Baro = " + Tekst; 312 //Grafiek(0, 188, 950, Tekst, "B"); //startadres,stopadres, waardeverekening baro 313 314 if (Baro > 950 & Baro <= 960) { 315 BR = 955; 316 } 317 else if (Baro > 960 & Baro <= 970) { 318 BR = 965; 319 } 320 else if (Baro > 970 & Baro <= 980) { 321 BR = 975; 322 } 323 else if (Baro > 980 & Baro <= 990) { 324 BR = 985; 325 } 326 else if (Baro > 990 & Baro <= 1000) { 327 BR = 995; 328 } 329 else if (Baro > 1000 & Baro <= 1010) { 330 BR = 1005; 331 } 332 else if (Baro > 1010 & Baro <= 1020) { 333 BR = 1015; 334 } 335 else if (Baro > 1020 & Baro <= 1030) { 336 BR = 1025; 337 } 338 else if (Baro > 1030 & Baro <= 1040) { 339 BR = 1035; 340 } 341 else if (Baro > 1040 & Baro <= 1050) { 342 BR = 1045; 343 } 344 Sensortekst(BR - 5, Baro, BR + 5, "Sch.: 1 mBar ", GREEN); 345 } 346 347 SensorW( Baro, BR - 5, 10); 348 break; 349 //========================== 350 case 14 : // 1110 zoommode x 5 351 if (ddd[14] == 0) 352 { 353 dddInstellen(14); 354 // String Tekst; 355 // Tekst = Temp; 356 // Tekst = "Temp = " + Tekst; 357 //Grafiek(1000, 1188, 0, Tekst, "T"); //startadres,stopadres, waardeverekening temp 358 if (Temp > 0 & Temp < 10) { 359 TM = 5; 360 } 361 else if (Temp > 10 & Temp <= 20) { 362 TM = 15; 363 } 364 else if (Temp > 20 & Temp <= 30) { 365 TM = 25; 366 } 367 else if (Temp > 30 & Temp <= 40) { 368 TM = 35; 369 } 370 else if (Temp > 40 & Temp <= 50) { 371 TM = 45; 372 } 373 Sensortekst(TM - 5, Temp, TM + 5, "Sch.: 1 gr. C ", RED); 374 } 375 SensorW( Temp, TM - 5, 10); 376 break; 377 //================================== 378 case 15 : // 1111 379 if (ddd[15] == 0) 380 { 381 dddInstellen(15); 382 //String Tekst; 383 //Tekst = Hygro; 384 //Tekst = "Hygro = " + Tekst; 385 //Grafiek(2000, 2188, 0, Tekst, "B"); //startadres,stopadres, waardeverekening hygro 386 if (Hygro > 0 & Hygro < 10) { 387 HG = 5; 388 } 389 else if (Hygro > 10 & Hygro <= 20) { 390 HG = 15; 391 } 392 else if (Hygro > 20 & Hygro <= 30) { 393 HG = 25; 394 } 395 else if (Hygro > 30 & Hygro <= 40) { 396 HG = 35; 397 } 398 else if (Hygro > 40 & Hygro <= 50) { 399 HG = 45; 400 } 401 else if (Hygro > 50 & Hygro <= 60) { 402 HG = 55; 403 } 404 else if (Hygro > 60 & Hygro <= 70) { 405 HG = 65; 406 } 407 else if (Hygro > 70 & Hygro <= 80) { 408 HG = 75; 409 } 410 else if (Hygro > 80 & Hygro <= 80) { 411 HG = 85; 412 } 413 else if (Hygro > 90 & Hygro <= 100) { 414 HG = 95; 415 } 416 417 Sensortekst(HG - 5, Hygro, HG + 5, "Sch.: 10 % ", BLUE); 418 } 419 420 SensorW( Hygro, HG - 5, 10); 421 break; 422 //================================== 423 } 424 425 426 //=============een keer per dag max en min van temp en hygro resetten =============== 427 TijdcurrentMillis = millis(); 428 if (TijdcurrentMillis - TijdpreviousMillis > Tijdinterval) 429 { 430 TijdpreviousMillis = TijdcurrentMillis; 431 float2byte (1200, Temp, 0); 432 float2byte (1202, Temp, 0); 433 float2byte (2200, Hygro, 0); 434 float2byte (2202, Hygro, 0); 435 } 436 437 //============een keer per 30 seconden sensor uitlezen =========================== 438 currentMillis = millis(); 439 if (currentMillis - previousMillis > interval) 440 { 441 previousMillis = currentMillis; 442 dddInstellen(16); 443 SensorLDUitlezen(); 444 445 } 446 447 //============= een keer per kwartier data naar eeprom ============= 448 449 BcurrentMillis = millis(); 450 if (BcurrentMillis - BpreviousMillis > Binterval) 451 { 452 BpreviousMillis = BcurrentMillis; 453 454 //============== baro ====================== 455 float2byte (190, Baro, 950); 456 dataopslaan(0, 190); 457 458 // for (int i = 0; i < sizeof(xy); i++) { 459 // byte sb = mem.read(0 + i); 460 // Serial.print("["); 461 // Serial.print(0 + i); 462 // Serial.print("] = "); 463 // Serial.println(sb); 464 //} 465 466 //================= temp ================= 467 float2byte (1190, Temp, 0); 468 dataopslaan(1000, 1190); 469 470 //================= hygro ================= 471 float2byte (2190, Hygro, 0); 472 dataopslaan(2000, 2190); 473 474 //for (int i = 0; i < sizeof(xy); i++) 475 // { 476 // byte sb = mem.read(2000 + i); 477 // Serial.print("["); 478 // Serial.print(2000 + i); 479 // Serial.print("] = "); 480 // Serial.println(sb); 481 // } 482 } 483 // ====================================== 484 485 486}// einde void loop 487//----------------------------------------------------------------------------- 488void dataopslaan(int startA, int stopA) { 489 byte tt; 490 int xx = 0; 491 for (int addr = startA; addr < stopA; addr += 2) 492 { 493 tt = mem.read(addr + 2); 494 xy[xx] = tt; 495 tt = mem.read(addr + 3); 496 xy[xx + 1] = tt; 497 xx += 2; 498 } 499 mem.write(startA, (byte*)xy, sizeof(xy)); 500} 501//----------------------------------------------------------------------------- 502void float2byte (int adres, float sw, float af) { 503 int sw1; 504 sw1 = sw; 505 testH = sw - af; 506 testL = (sw - sw1) * 100; 507 mem.write(adres, testH); 508 mem.write(adres + 1, testL); 509 510} 511//------------------------------------------------------------------- 512float byte2float ( int adres, float bij) { 513 float SW; 514 float ttl; 515 testH = mem.read(adres); 516 testL = mem.read(adres + 1); 517 ttl = testL; 518 SW = testH + ( ttl / 100); 519 SW += bij; 520 return SW; 521} 522//-------------------------------------------------------------------------------- 523void dddInstellen(byte een) { 524 for (byte x = 0 ; x < 16; x++) 525 { 526 ddd[x] = 0;// alles op nul zetten 527 } 528 ddd[een] = 1;// 1 van de 16 op 1 zetten, zodat de routine 1 maal doorlopen wordt 529} 530// --------------------------------------------------------------------- 531 532void SensorLDUitlezen() { 533 float dummy; 534 dummy = bmp.readTemperature(); 535 Baro = bmp.readPressure(); 536 Baro = (Baro / 100); 537 538 539 540 sht.read(); 541 542 Temp = sht.getTemperature(); 543 Hygro = sht.getHumidity(); 544 Temp = Temp - 1 ; 545 maxmin(200, Baro, 950); 546 maxmin(1200, Temp, 0); 547 maxmin(2200, Hygro, 0); 548 549 //Serial.print("baro min = "); 550 //Serial.println(Minimum); 551 //Serial.print("baro max = "); 552 //Serial.println(Maximum); 553} 554//------------------------------------------------------------------------------------------- 555void maxmin(int startA, float Sensor, float erbij) { 556 float waarde; 557 558 waarde = byte2float (startA, erbij);// adres, waarde erbij,= minimum 559 if (Sensor < waarde) { 560 float2byte(startA, Sensor, erbij); 561 } 562 waarde = byte2float (startA + 2, erbij); //adres, waarde erbij, = maximum 563 if (Sensor > waarde) { 564 float2byte(startA + 2, Sensor, erbij); 565 } 566} 567//-------------------------------------------------------------------------------------------- 568void CHBtekst() { 569 BarCode(0, 10, 11); 570 digitalWrite(LedRange, LOW); 571 String Temp1; 572 String Hygro1; 573 String Baro1; 574 digitalWrite(TFTL, HIGH); 575 Temp1 = String(Temp); 576 Temp1 += " C "; 577 Hygro1 = String(Hygro); 578 Hygro1 += " % "; 579 Baro1 = String(Baro); 580 Baro1 += " mB "; 581 tft.fillScreen(BLACK); 582 tft.setTextSize(3); 583 tft.setTextColor(RED, 0); 584 tft.setCursor(10, 50); // Set position (x,y) 585 tft.println("Temp: "); // Print a text or value 586 tft.setCursor(120, 50); // Set position (x,y) 587 tft.println(Temp1); // Print a text or value 588 589 tft.setTextColor(BLUE, 0); // blauw Set color of text. First is the color of text and after is color of background 590 tft.setCursor(10, 100); // Set position (x,y) 591 tft.println("LV : "); // Print a text or value 592 tft.setCursor(120, 100); // Set position (x,y) 593 tft.println(Hygro1); // Print a text or value 594 595 tft.setTextColor(GREEN, 0); // groen Set color of text. First is the color of text and after is color of background 596 tft.setCursor(10, 150); // Set position (x,y) 597 tft.println("Atm : "); // Print a text or value 598 tft.setCursor(120, 150); // Set position (x,y) 599 tft.println(Baro1); // Print a text or value 600 601 float test ; 602 test = (BcurrentMillis - BpreviousMillis); 603 604 test = test / 900000; 605 //Serial.print("test : "); 606 //Serial.println(BcurrentMillis); 607 // Serial.println(BpreviousMillis); 608 // Serial.println(test); 609 610 611 612 for (byte x = 0 ; x < 11; x++) { 613 tft.drawLine((x * 27) + 20, 210, (x * 27) + 20, 220, RED);// uurlijnen 614 } 615 tft.drawLine(20, 214, (test * 270) + 20, 214, RED); 616 tft.drawLine(20, 215, (test * 270) + 20, 215, RED); 617 tft.drawLine(20, 216, (test * 270) + 20, 216, RED); 618} 619 620 621//---------------------------------------------------------- 622void Sensortekst(int Min, float SW, int Max, String Tekst1, int kleur) { 623 String Sensor; 624 String Min1; 625 String Max1; 626 Sensor = SW; 627 Sensor += " "; 628 Min1 = Min; 629 Min1 += " "; 630 Max1 = Max; 631 Max1 += " "; 632 digitalWrite(TFTL, HIGH); 633 digitalWrite(LedRange, HIGH); 634 tft.fillScreen(BLACK); 635 tft.setTextSize(3); 636 if (kleur == GREEN) { 637 tft.setTextColor(GREEN, 0); // rood Set color of text. First is the color of text and after is color of background 638 tft.setCursor(10, 0); // Set position (x,y) 639 tft.println("--- Barometer --- "); 640 } 641 else if (kleur == RED) { 642 tft.setTextColor(kleur, 0); // rood Set color of text. First is the color of text and after is color of background 643 tft.setCursor(10, 0); // Set position (x,y) 644 tft.println("-- Thermometer -- "); 645 } 646 else if (kleur == BLUE) { 647 tft.setTextColor(kleur, 0); // rood Set color of text. First is the color of text and after is color of background 648 tft.setCursor(10, 0); // Set position (x,y) 649 tft.println("-- Hygrometer -- "); 650 } 651 652 tft.setTextColor(kleur, 0); // rood Set color of text. First is the color of text and after is color of background 653 tft.setCursor(10, 50); // Set position (x,y) 654 tft.println("Max : "); // Print a text or value 655 tft.setCursor(120, 50); // Set position (x,y) 656 tft.println(Max1); // Print a text or value 657 658 659 660 //tft.setTextColor(kleur, 0); // blauw Set color of text. First is the color of text and after is color of background 661 tft.setCursor(10, 100); // Set position (x,y) 662 tft.println("Nu : "); // Print a text or value 663 tft.setCursor(120, 100); // Set position (x,y) 664 tft.println(Sensor); // Print a text or value 665 666 667 //tft.setTextColor(kleur, 0); // groen Set color of text. First is the color of text and after is color of background 668 tft.setCursor(10, 150); // Set position (x,y) 669 tft.println("Min : "); // Print a text or value 670 tft.setCursor(120, 150); // Set position (x,y) 671 tft.println(Min1); // Print a text or value 672 673 //tft.setTextColor(kleur, 0); 674 tft.setCursor(10, 200); // Set position (x,y) 675 tft.println(Tekst1); // Print a text or valu 676 677} 678 679//---------------------------------------------------------- 680void Sensor(float SW, int S1, float S2 ) { 681 byte SW1; 682 digitalWrite(LedRange, HIGH); 683 SW1 = ((SW - S1) * S2) + 0.5; 684 LB = Eenh(SW1); 685 HB = Tiental(SW1); 686} 687//---------------------------------------------------------- 688void SensorW(float SW, int S1, float S2 ) { 689 Sensor(SW, S1, S2); 690 if (LB == 0 & HB == 0) { 691 BarCode(0, 10, 11); 692 } 693 else { 694 BarMode(LB, HB); 695 } 696} 697//------------------------------------------------------------ 698void SensorD (float SW, int S1, float S2 ) { 699 Sensor(SW, S1, S2); 700 if (LB == 0 & HB == 0) { 701 BarCode(0, 10, 11); 702 } 703 else { 704 DotMode(LB, HB); 705 } 706} 707//------------------------------------------------------------ 708void Grafiek(int StartA, int StopA, float ErBij, String text, String ID7) { 709 float Schaal; 710 int Plot1; 711 int Plot2; 712 float f; 713 float AantalS; 714 float eep1; 715 float eep2; 716 float Min = 2000; 717 float Max = 0; 718 float Sfactor; 719 digitalWrite(TFTL, HIGH); 720 for (int x = StartA ; x < StopA; x += 2) { 721 eep1 = byte2float (x , ErBij); 722 //Serial.print("adres : "); 723 //Serial.print(x); 724 //Serial.print(" waarde : "); 725 //Serial.println(eep1); 726 if ( eep1 < Min) { 727 Min = eep1; 728 } 729 if ( eep1 > Max) { 730 Max = eep1; 731 } 732 } 733 734 f = Max - Min; 735 if (f > 10) { 736 AantalS = (f / 2) + 3; 737 Sfactor = 110 / AantalS; 738 } 739 else if (f < 2) { 740 AantalS = 2; 741 Sfactor = 110 / AantalS; // 11 is (220/2) / AantalS) 742 } 743 else 744 { 745 AantalS = 6; 746 Sfactor = 110 / AantalS; // 11 is (220/2) / AantalS) 747 // AantalS = helft aantal lijnen y-as 748 } 749 750 Schaal = ((Max + Min) / 2) - AantalS; 751 752 tft.fillScreen(BLACK); 753 tft.setTextSize(2); 754 755 756 tft.setTextColor(WHITE, 0); 757 758 tft.setCursor(5, 223); // Set position (x,y) 759 tft.println("-24u"); // Print a text or value 760 761 tft.setCursor(80, 223); // Set position (x,y) 762 tft.println("-18u"); // Print a text or value 763 764 tft.setCursor(155, 223); // Set position (x,y) 765 tft.println("-12u"); // Print a text or value 766 767 tft.setCursor(230, 223); // Set position (x,y) 768 tft.println("-6u"); 769 770 tft.drawLine(20, 0, 20, 220, WHITE); 771 tft.drawLine(10, 220, 320, 220, WHITE); 772 773 for (byte y = 0 ; y < AantalS * 2; y++) { 774 tft.drawLine(10, y * Sfactor, 320, y * Sfactor, 0x1100); 775 } 776 for (byte x = 1 ; x < 4; x++) { 777 tft.drawLine((x * 75) + 20, 0, (x * 75) + 20, 220, 0x1100);// uurlijnen 778 } 779 for (byte y = 0 ; y < (AantalS * 2); y++) { 780 tft.drawLine(10, y * Sfactor, 20, y * Sfactor, 0x1100);// y lijnen 781 } 782 783 int xas = 1; 784 for (int x = StartA ; x < StopA; x += 2) { 785 786 eep1 = byte2float (x, ErBij); 787 eep2 = byte2float (x + 2 , ErBij); 788 Plot1 = 220 - ((eep1 - Schaal) * Sfactor); 789 Plot2 = 220 - ((eep2 - Schaal) * Sfactor); 790 // Serial.print("plot1 : "); 791 //Serial.print(Plot1); 792 //Serial.print(" plot2 : "); 793 // Serial.println(Plot2); 794 795 tft.drawLine( 20 + (xas * 3.26), Plot1, 20 + (( xas + 1) * 3.26), Plot2, RED); 796 797 xas++; 798 799 800 } 801 tft.setTextColor(RED, 0); 802 tft.setCursor(100, 5); // Set position (x,y) 803 tft.println(text); // Print a text or value 804 int zz = 1; 805 if (ID7 == "T") { 806 zz = 2; 807 } 808 if (ID7 == "B" | ID7 == "T") { // "|" = OR functie 809 xas = 1; 810 for (int x = StartA ; x < StopA; x += 2) { 811 eep1 = byte2float (x, ErBij); 812 eep2 = byte2float (x + 2 , ErBij); 813 Plot1 = 220 - ((eep1 - Schaal) * Sfactor); 814 Plot2 = 220 - ((eep2 - Schaal) * Sfactor); 815 tft.drawLine(20 + (xas * 3.26), Plot1, 20 + (( xas + 1) * 3.26), Plot2, YELLOW); 816 SensorD( eep1, ErBij, zz); 817 delay(50); 818 tft.drawLine( 20 + (xas * 3.26), Plot1, 20 + (( xas + 1) * 3.26), Plot2, RED); 819 xas++; 820 821 } 822 } 823} 824//------------------------------------------------------------------------------------------ 825void WeerTrend() { 826 float Uur3; 827 float Uur6; 828 float Uur12; 829 float Uur24; 830 float eep1; 831 float eep2; 832 digitalWrite(TFTL, HIGH); 833 eep1 = byte2float (188, 950); 834 eep2 = byte2float (164, 950); 835 Uur3 = eep1 - eep2; 836 eep2 = byte2float (140, 950); 837 Uur6 = eep1 - eep2; 838 eep2 = byte2float (92, 950); 839 Uur12 = eep1 - eep2; 840 eep2 = byte2float (0, 950); 841 Uur24 = eep1 - eep2; 842 tft.fillScreen(BLACK); 843 tft.setTextSize(3); 844 tft.setTextColor(GREEN, 0); // rood Set color of text. First is the color of text and after is color of background 845 tft.setCursor(10, 0); // Set position (x,y) 846 tft.println("--- Luchtdruk ---"); 847 848 tft.setCursor(10, 33); // Set position (x,y) 849 tft.println("Max : "); // Print a text or value 850 tft.setCursor(120, 33); // Set position (x,y) 851 eep1 = byte2float (202, 950); 852 tft.println(eep1); // Print a text or value 853 854 tft.setCursor(10, 66); // Set position (x,y) 855 tft.println("Min : "); // Print a text or value 856 tft.setCursor(120, 66); // Set position (x,y) 857 eep2 = byte2float (200, 950); 858 tft.println(eep2); // Print a text or value 859 860 tft.setCursor(10, 99); // Set position (x,y) 861 tft.println("3 uur : "); // Print a text or value 862 tft.setCursor(200, 99); // Set position (x,y) 863 tft.println(Uur3); // Print a text or value 864 865 tft.setCursor(10, 133); // Set position (x,y) 866 tft.println("6 uur : "); // Print a text or value 867 tft.setCursor(200, 133); // Set position (x,y) 868 tft.println(Uur6); // Print a text or value 869 870 tft.setCursor(10, 166); // Set position (x,y) 871 tft.println("12 uur : "); // Print a text or value 872 tft.setCursor(200, 166); // Set position (x,y) 873 tft.println(Uur12); // Print a text or value 874 875 tft.setCursor(10, 210); // Set position (x,y) 876 tft.println("24 uur : "); // Print a text or value 877 tft.setCursor(200, 210); // Set position (x,y) 878 tft.println(Uur24); // Print a text or value 879 880} 881//-------------------------------------------------------------- 882void THData() { 883 float eep2; 884 digitalWrite(TFTL, HIGH); 885 tft.fillScreen(BLACK); 886 tft.setTextSize(3); 887 tft.setTextColor(RED, 0); // rood Set color of text. First is the color of text and after is color of background 888 tft.setCursor(10, 0); // Set position (x,y) 889 tft.println("-- Temperatuur --"); 890 tft.setCursor(10, 33); // Set position (x,y) 891 tft.println("Max : "); // Print a text or value 892 tft.setCursor(120, 33); // Set position (x,y) 893 eep2 = byte2float (1202, 0); 894 tft.println(eep2); // Print a text or value 895 896 tft.setCursor(10, 66); // Set position (x,y) 897 tft.println("Min : "); // Print a text or value 898 tft.setCursor(120, 66); // Set position (x,y) 899 eep2 = byte2float (1200, 0); 900 tft.println(eep2); // Print a text or value 901 902 tft.setTextColor(BLUE, 0); // rood Set color of text. First is the color of text and after is color of background 903 tft.setCursor(10, 99); // Set position (x,y) 904 tft.println("--- Hygro ---"); 905 tft.setCursor(10, 133); // Set position (x,y) 906 tft.println("Max : "); // Print a text or value 907 tft.setCursor(120, 133); // Set position (x,y) 908 eep2 = byte2float (2202, 0); 909 tft.println(eep2); // Print a text or value 910 911 tft.setCursor(10, 166); // Set position (x,y) 912 tft.println("Min : "); // Print a text or value 913 tft.setCursor(120, 166); // Set position (x,y) 914 eep2 = byte2float (2200, 0); 915 tft.println(eep2); // Print a text or value 916} 917//-------------------------------------------------------------- 918void DotMode(byte LB, byte HB) { 919 if (LB == 0) { 920 HB = HB - 1; 921 } 922 digitalWrite(latchPin, LOW); 923 shiftOut(dataPin, clockPin, MSBFIRST, rij2[LB]); 924 shiftOut(dataPin, clockPin, MSBFIRST, rij1[LB]); 925 shiftOut(dataPin, clockPin, MSBFIRST, kolom2BM[HB]); 926 shiftOut(dataPin, clockPin, MSBFIRST, kolom1BM[HB]); 927 digitalWrite(latchPin, HIGH); 928 929} 930//---------------------------------------------------------- 931 932void BarCode(int DL, byte LB, byte HB) { 933 digitalWrite(latchPin, LOW); 934 shiftOut(dataPin, clockPin, MSBFIRST, rij2BM[LB]); 935 shiftOut(dataPin, clockPin, MSBFIRST, rij1BM[LB]); 936 shiftOut(dataPin, clockPin, MSBFIRST, kolom2BM[HB]); 937 shiftOut(dataPin, clockPin, MSBFIRST, kolom1BM[HB]); 938 digitalWrite(latchPin, HIGH); 939 delayMicroseconds(DL); 940} 941 942//----------------------------------------------------------- 943 944void BarMode(byte LB, byte HB) { 945 int DL; 946 947 //LB = 6; 948 //HB = 7; 949 //Serial.println(LDruk); 950 //Serial.println(HB); 951 //Serial.println(LB); 952 switch (HB) { 953 case 0: 954 DL = 100; 955 break; 956 case 1: 957 DL = 200; 958 BarCode(DL, 0, 0);// LB,HB 959 break; 960 case 2: 961 DL = 300; 962 BarCode(DL, 0, 0); 963 BarCode(DL, 0, 1); 964 break; 965 case 3: 966 DL = 400; 967 for (byte x = 0; x <= 2; x++) 968 { 969 BarCode(DL, 0, x); 970 } 971 break; 972 case 4: 973 DL = 500; 974 for (byte x = 0; x <= 3; x++) 975 { 976 BarCode(DL, 0, x); 977 } 978 break; 979 case 5: 980 DL = 600; 981 for (byte x = 0; x <= 4; x++) 982 { 983 BarCode(DL, 0, x); 984 } 985 break; 986 case 6: 987 DL = 700; 988 for (byte x = 0; x <= 5; x++) 989 { 990 BarCode(DL, 0, x); 991 } 992 break; 993 case 7: 994 DL = 800; 995 for (byte x = 0; x <= 6; x++) 996 { 997 BarCode(DL, 0, x); 998 } 999 break; 1000 case 8: 1001 DL = 900; 1002 for (byte x = 0; x <= 7; x++) 1003 { 1004 BarCode(DL, 0, x); 1005 } 1006 break; 1007 case 9: 1008 DL = 900; 1009 for (byte x = 0; x <= 8; x++) 1010 { 1011 BarCode(DL, 0, x); 1012 } 1013 break; 1014 default: 1015 BarCode(0, 10, 11); 1016 digitalWrite(LedRange, LOW); 1017 break; 1018 } 1019 if (LB > 0) { 1020 BarCode(DL, LB, HB); 1021 } 1022} 1023 1024 1025//------------------------------------------- 1026 1027 1028void Bartest() { 1029 1030 tft.setTextColor(0xF9E0, 0); 1031 tft.setTextSize(5); 1032 for (byte x = 1; x <= 100; x++) { 1033 LB = Eenh(x); 1034 HB = Tiental(x); 1035 DotMode(LB, HB); 1036 tft.setCursor(150, 80); 1037 tft.println(x); 1038 delay(15); 1039 } 1040 //tft.fillScreen(BLACK); 1041 tft.setTextSize(3); 1042 1043} 1044 1045//----------------------------------------- 1046byte Eenh(byte waarde) { 1047 byte test = waarde % 10;// % = modulo 1048 return test; 1049} 1050//--------------------------------------------- 1051byte Tiental(byte waarde) { 1052 byte test2 = waarde / 10; 1053 return test2; 1054} 1055//-------------------------------------------------- 1056
Comments
Only logged in users can leave comments