1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
| //https://www.aranacorp.com/fr/utilisation-dun-shield-tft-lcd-avec-arduino/
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
//#include <Fonts/FreeSans10pt7b.h>
//#include <Fonts/FreeSans12pt7b.h>
//#include <Fonts/FreeSerif12pt7b.h>
//#include <FreeDefaultFonts.h>
#include <math.h>
#include <DHT.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include "SPI.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include "Adafruit_Sensor.h"
#include <Adafruit_NeoPixel.h>
#include <Servo.h>
#include "GravityTDS.h"
#include <SFE_BMP180.h>
SFE_BMP180 bmp180;
// capteur TDS
//Capteur PH
const int analogInPin = A8;
int sensorValue = 0;
unsigned long int avgValue;
//float b;
int buf[10],temp1=0;
String data1;
String b;
#define DHTPIN 37 // what digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// ALL Touch panels and wiring is DIFFERENT
DHT dht(DHTPIN, DHTTYPE);
SoftwareSerial nodemcu(14,15);//RX 15 et TX 14
#define ONE_WIRE_BUS 35
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
// On définit les variables
float tmin,tmax,tnow,tlast;//DS18B20
// On définit les variables
float tmin1,tmax1,tnow1,tlast1;//DHT11
// On définit les variables
float hmin,hmax,hnow,hlast;
#define MINPRESSURE 200
#define MAXPRESSURE 1000
//Ultrasonic Sensor
const int trigPin = 16;
const int echoPin = 17;
//Define Variables
long duration = 0;
long distance = 0;
long distanceOld = 0;
// copy-paste results from TouchScreen_Calibr_native.ino
//3.5 Calibration
const int XP = 8, XM = A2, YP = A3, YM = 9; //320x480 ID=0x9486
const int TS_LEFT = 151, TS_RT = 880, TS_TOP = 946, TS_BOT = 161;
//2.8 Calbiration
//const int XP=8,XM=A2,YP=A3,YM=9; //240x320 ID=0x9341
//const int TS_LEFT=907,TS_RT=120,TS_TOP=74,TS_BOT=913;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
TSPoint p;
Adafruit_GFX_Button on_btn, off_btn, page1_btn, page2_btn, page3_btn, page4_btn;
Adafruit_GFX_Button ok_btn, cncl_btn, plus_btn, minus_btn;
Adafruit_GFX_Button menu_btn, info_btn, back_btn;
int pixel_x, pixel_y; //Touch_getXY() updates global vars
// Button calibration
int margin = 5;
int btnWidth = 100;
int btnHeight = 40;
int btnY = 200;
// Software variable
bool enable_nuit = false;
int parameter = 50, old_parameter = 50;
float rh; // relative humidity in %
float t; //temperature in celsius
float td; //dew point in celsius
//Décalage pour létalonnage de la température
// uint8_t Compenser = 5;
// Color definitions
#define WHITE 0x0000
#define BLUE 0xFFE0
#define RED 0x07FF
#define MAGENTA 0x07E0
#define CYAN 0xF800
#define GREEN 0xF81F
#define YELLOW 0x001F
#define BLACK 0xFFFF
#define ORANGE 0x0000FF
#define MAUVE 0x0D20
//**********************ANEMOMETRE *******************
//Pin pour contact reed, Digital-2 pour Interrupt 0
#define REEDPIN 18
// Interruption matérielle pour la broche Reed
#define REEDINTERRUPT 0 // potard
// La circonférence en mm a été déterminée dans la soufflerie à laide du Volkswindmesser comme référence
#define RADUMFANG 2200
#define ledalarm 29 // LED ALARM sortie négatif (-)
#define resetmaxpin 33 // reset max Pin (button)
#define resetalarmpin 34 // reset Alarm Pin (button)
//********************** FIN ANEMOMETRE *******************
namespace pin {
const byte tds_sensor = A9;
}
namespace device {
float aref = 4.3;
}
namespace sensor {
float ec = 0;
unsigned int tds = 0;
float waterTemp = 0;
float ecCalibration = 1;
}
enum pageId {
MENU,
TEMPERATURES,
ANEMOMETRE,
PRESSION,
PISCINE,
INFO
};
unsigned int currentPage = MENU, oldPage = -1;
long int data;
float sdata1 = 0; // temperature DS18B20
float sdata2 = 0; // Valeur du PH
float sdata3 = 0; // Angle volet
float sdata4 = 0; // Alarme vent
float sdata5 = 0; // vent MAX
float sdata6 = 0; // vent Actuel
float sdata7 = 0; // Altiude
float sdata8 = 0; // Pression atmospherique
float sdata9 = 0; // Température du boitier
float sdata10 = 0; // Niveau
float sdata11 = 0; // Valeur PH
float sdata12 = 0; // Valeur TDS
float sdata13 = 0; // Valeur piscine Max
float sdata14 = 0; // Valeur piscine Min
float sdata15 = 0; // Valeur extérieur Max
float sdata16 = 0; // Valeur extérieur Min
float sdata17 = 0; // Valeur extérieur Max
float sdata18 = 0; // Valeur humidité Max
float sdata19 = 0; // Valeur humidité Min
String cdata; // complete data
void setup()
{
Serial.begin(9600);
pinMode(trigPin, OUTPUT); //sets the trigPin as an Output
pinMode(echoPin, INPUT); //sets the echoPin as an Input
Serial.setTimeout(10);
Serial.println("Ready"); //Test the serial monitor
// initialize BMP180
bool success = bmp180.begin();
if(success) {
Serial.println("BMP180 init success");
}
nodemcu.begin(9600);
// float tmin,tmax,tnow,tlast,tminout,tmaxout,tnowout,tlastout,hmin,hmax,hnow,hlast;
dht.begin();
DS18B20.begin();
// on initialise la température max et min.DS18B20
tmin = 125;
tmax = -55;
tlast = 0;
// on initialise la température max et min.DHT11
tmin1 = 125;
tmax1 = -55;
tlast1 = 0;
// on initialise l'humidité max et min.DHT11
hmin = 100;
hmax = 0;
hlast = 0;
//init TFTTouch
uint16_t ID = tft.readID();
Serial.print("TFT ID = 0x");
Serial.println(ID, HEX);
Serial.println(F("Calibrate for your Touch Panel"));
if (ID == 0xD3D3) ID = 0x9341; //for 3.5" TFT LCD Shield , 0x9341 for 2.8" TFT LCD Shield
tft.begin(ID);
tft.setRotation(1); //0-PORTRAIT 1-PAYSAGE 2-REVERSE PORTRAIT 3-REVERSE PAYSAGE
//tft.setFont(&FreeSmallFont);
currentPage = MENU; // Indicates that we are at Home Screen
Serial.println("Home Page");
pinMode(REEDPIN, INPUT_PULLUP); // Reedkontakt direkt und ohne Widerstand angeschlossen
attachInterrupt(digitalPinToInterrupt(REEDPIN), reedISR, FALLING);
Serial.begin(9600);
pinMode(resetmaxpin, INPUT_PULLUP); // Resetmax Taster direkt und ohne Widerstand angeschlossen (gegen ground)
pinMode(resetalarmpin, INPUT_PULLUP); // Resetalarm Taster direkt und ohne Widerstand angeschlossen (gegen ground)
}
//******************************ANEMOMETRE **********************************
float ms2; //globale Variable Speed in m/s
float msmax = 0; //Maximalwert
unsigned long umin; // U/min
int alarm; // Limite dalarme en m/s (m/s)
volatile byte reedCountSum;
volatile long reedMillisSum;
unsigned long lastReedMillis;
unsigned long gesamtUmdrehungen = 0; //4545300;
unsigned long interval; // update tft/LED interval (milliseconds)
unsigned long previousMillis = 0;
unsigned long intervalalarm = 200; // update Alarm Anzeige interval (milliseconds)
unsigned long previousMillisalarm = 0;
unsigned long currentMillis;
int potpin = 10; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
//******************************FIN ANEMOMETRE **********************************
bool down ;
void loop()
{
tnow = DS18B20.getTempCByIndex(0);
if(tnow!=tlast) {
tlast=tnow;
if(tnow<tmin)
tmin=tnow;
if(tnow>tmax)
tmax=tnow;
Serial.print(" PISCINE ACTUEL");
Serial.print(tnow);
Serial.print("MAXI out ");
Serial.print(tmax);
Serial.print("MINI out ");
Serial.print(tmin);
Serial.println(" *C");
}
tnow1 = dht.readTemperature(0);
if(tnow1!=tlast1) {
tlast1=tnow1;
if(tnow1<tmin1)
tmin1=tnow1;
if(tnow1>tmax1)
tmax1=tnow1;
Serial.print("EXTERIEUR ACTUEL");
Serial.print(tnow1);
Serial.print("MAXI out ");
Serial.print(tmax1);
Serial.print("MINI out ");
Serial.print(tmin1);
Serial.println(" *C");
}
hnow = dht.readHumidity(0);
if(hnow!=hlast) {
hlast=hnow;
if(hnow<hmin)
hmin=hnow;
if(hnow>hmax)
hmax=hnow;
Serial.print("HUMIDITE ");
Serial.print(hnow);
Serial.print("HUMIDITE MAX ");
Serial.print(hmax);
Serial.print("HUMIDITE MIN");
Serial.print(hmin);
Serial.println("%");
}
byte umdrehungen;
unsigned long zeit;
float kph, kilometer, ms;
//*****************affichage de l'alarme ***********************
if (ms2 > alarm) {
digitalWrite (ledalarm,HIGH);
delay (50);
digitalWrite (ledalarm,LOW);
}
char buffer[10];
noInterrupts(); // Interrupts sperren
umdrehungen=reedCountSum;// Zählvariable umkopieren
reedCountSum=0; // Zählvariable auf 0 zurücksetzen
zeit=reedMillisSum; // Zeitzähler umkopieren
reedMillisSum=0; // Zeitzähler auf 0 zurücksetzen
interrupts(); // Interrupts wieder zulassen
gesamtUmdrehungen+= umdrehungen; // Aufsummieren aller Radumdrehungen
kilometer=(float)gesamtUmdrehungen*(float)RADUMFANG/1000000.0; // Kilometerzähler
if (umdrehungen>0){
kph=float(RADUMFANG)*(float)umdrehungen/(float)zeit*3.6;
ms=float(RADUMFANG)*(float)umdrehungen/(float)zeit;
umin=umdrehungen*60000/zeit; }
else {
kph=0.0; //Définir zéro si aucun tour na été trouvé
umin = 0; } //Définir zéro si aucun tour na été trouvé
// ms = kph/3.6; //aus km/h mach m/s - kmh/3.6
ms2 = kph; //variable ms in ms2 global kopieren
val = analogRead(potpin); // Lire la valeur du potentiometre (valeur entre 0 and 1023)
alarm = map(val, 0, 1023, 0, 200); // scalieren der Potistellung (0-30m/s)
digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
readTdsQuick();
delay(10);
tnow = DS18B20.getTempCByIndex(0);
//capteur TDS
//Serial.print(tdsValue,0);
Serial.println("ppm");
//Capteur PH
for(int i=0;i<10;i++)
{
buf[i]=analogRead(analogInPin);
delay(10);
}
for(int i=0;i<9;i++)
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
t=buf[i];
buf[i]=buf[j];
buf[j]=t;
}
}
}
avgValue=0;
for(int i=2;i<8;i++)
avgValue+=buf[i];
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034/2;
if(distance!=distanceOld){
getDistance(distanceOld, BLACK);
getDistance(distance, WHITE);
}
distanceOld = distance;
delay(100);
// take measurement
double T, P, A;
bool success = measureBMP180(T, P, A);
// don't update for unsuccessful measurement
if (!success)
return;
//******************************ANEMOMETRE **********************************
//Adapter lintervalle dévaluation en fonction du régime
if (ms2 < 1) {
interval = 4000; }
if (ms2 >= 1 && ms2 < 2) {
interval = 2100; }
if (ms2 >= 2 && ms2 < 3) {
interval = 1100; }
if (ms2 >= 3 && ms2 < 4) {
interval = 800; }
if (ms2 >= 4 && ms2 < 6 ) {
interval = 600; }
if (ms2 > 6) {
interval = 400; }
// Actualisation de laffichage après le réglage de linteval
currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
tachoAnzeige();
previousMillis = currentMillis;
}
// Actualisation de laffichage Alaram après linterval défini
if (currentMillis - previousMillisalarm >= intervalalarm)
{
previousMillisalarm = currentMillis;
}
//Suppression des 10 premières rotations ou réinitialisation du bouton pour rétablir la valeur maximale
if (gesamtUmdrehungen < 10 || digitalRead(resetmaxpin) == LOW ) {
msmax = 0; }
//Réinitialiser les rotations globales avant que le présentoir ne déborde
if (gesamtUmdrehungen > 4545430) {
gesamtUmdrehungen = 0; }
char status;
float pHVol=(float)avgValue*5.0/1024/4.3;
float phValue = -5.70 * pHVol + 42.8;
sdata1 = tnow;
sdata2 = tnow1 ;// Valeur température extérieure DHT
sdata3 = hnow ;// Valeur humidité DHT
sdata4 = alarm ;// Valeur réglage alarme vent
sdata5 = msmax ;// Valeur vent max
sdata6 = ms2 ;// Valeur vent actuel
// sdata7 = al ;//Altitude
// sdata8 = P+12 ;// pression
// sdata9 = T ; // température boitier
sdata10 = distance ; // Niveau d'eau piscine / bassin
sdata11 = phValue ;// Valeur PH
sdata12 = sensor::tds ;// Valeur TDS
sdata13 = tmax ;// Valeur Max piscine
sdata14 = tmin ;// Valeur Min piscine
sdata15 = sensor::ec ;// Valeur Max extérieur
sdata16 = tmax1 ;// Valeur Min extérieur
sdata17 = tmin1 ;// Valeur Max extérieur
sdata18 = hmin ;// Valeur Max extérieur
sdata19 = hmin ;// Valeur Max extérieur
Serial.print("Temperature DS18B20 = ");
Serial.print(tnow);
Serial.print(tmax);
Serial.print(tmin);
Serial.println(" *C");
switch (currentPage) {
case MENU: //Menu page
if (currentPage != oldPage) drawMenuScreen();
page1_btn.press(down && page1_btn.contains(pixel_x, pixel_y));
page2_btn.press(down && page2_btn.contains(pixel_x, pixel_y));
page3_btn.press(down && page3_btn.contains(pixel_x, pixel_y));
page4_btn.press(down && page4_btn.contains(pixel_x, pixel_y));
if (page1_btn.justReleased())
page1_btn.drawButton();
if (page2_btn.justReleased())
page2_btn.drawButton();
if (page3_btn.justReleased())
page3_btn.drawButton();
if (page4_btn.justReleased())
page4_btn.drawButton();
if (page1_btn.justPressed()) {
page1_btn.drawButton(true);
currentPage = TEMPERATURES;
}
if (page2_btn.justPressed()) {
page2_btn.drawButton(true);
currentPage = ANEMOMETRE;
}
if (page3_btn.justPressed()) {
page3_btn.drawButton(true);
currentPage = PRESSION;
}
if (page4_btn.justPressed()) {
page4_btn.drawButton(true);
currentPage = PISCINE;
}
break;
case TEMPERATURES:// Menu TEMPERATURES
if (currentPage != oldPage) drawSensorScreen();
hmax,hnow,hlast;
float kph, kilometer, ms;
tft.setCursor (10,20);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print (" PISCINE ");
tft.setTextColor (BLUE,BLACK);
tft.setCursor (10,80);
tft.setTextSize (5);
tft.print (tnow);
tft.setTextColor (RED,BLACK);
tft.print (" C");
tft.setCursor (270,20);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print (" EXTERIEUR ");
tft.setTextColor (RED,BLACK);
tft.setCursor (260,80);
tft.setTextSize (5);
tft.print (tnow1);
tft.setTextColor (RED,BLACK);
tft.print (" C");
if(tnow1!=tlast1) {
tlast1=tnow1;
if(tnow1<tmin1)
tmin1=tnow1;
if(tnow1>tmax1)
tmax1=tnow1;}
if(tnow1>29){
tft.setCursor (260,80);
tft.setTextSize (5);
tft.setTextColor(RED,BLACK);
tft.print(tnow1);tft.print (' C');}
if(tnow1<29){
}
if(tnow!=tlast) {
tlast=tnow;
if(tnow<tmin)
tmin=tnow;
if(tnow>tmax)
tmax=tnow;}
if(tnow>29){
tft.setCursor (10,80);
tft.setTextSize (5);
tft.setTextColor(RED,BLACK);
tft.print(tnow);tft.print (' C');}
if(tnow<29){
}
tft.setCursor (7,180);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print (" HUMIDITE ");
tft.setTextColor (GREEN,BLACK);
tft.setCursor (10,230);
tft.setTextSize (5);
tft.print (hnow);
tft.setTextColor(CYAN,BLACK);
tft.print (" %");
tft.setCursor (270,180);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print (" VENT ");
tft.setTextColor (ORANGE,BLACK);
tft.setTextSize (5);
tft.setCursor (260,230);
dtostrf(ms2,2,1,buffer);
tft.print(buffer);
tft.setTextColor (CYAN,BLACK);
tft.setCursor (400,240);
tft.setTextSize (3);
tft.print ("km/h");
// updateTemp();
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
info_btn.press(down && info_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (info_btn.justReleased())
info_btn.drawButton();
if (menu_btn.justPressed()) {
menu_btn.drawButton(true);
currentPage = MENU;
}
if (info_btn.justPressed()) {
info_btn.drawButton(true);
currentPage = INFO;
}
break;
case ANEMOMETRE:// Menu ANEMOMETRE
if (currentPage != oldPage) drawSensorScreen();
byte umdrehungen;
unsigned long zeit;
char buffer[10];
noInterrupts(); // Interrupts sperren
umdrehungen=reedCountSum;// Zählvariable umkopieren
reedCountSum=0; // Zählvariable auf 0 zurücksetzen
zeit=reedMillisSum; // Zeitzähler umkopieren
reedMillisSum=0; // Zeitzähler auf 0 zurücksetzen
interrupts(); // Interrupts wieder zulassen
gesamtUmdrehungen+= umdrehungen; // Aufsummieren aller Radumdrehungen
kilometer=(float)gesamtUmdrehungen*(float)RADUMFANG/1000000.0; // Kilometerzähler
if (umdrehungen>0){
kph=float(RADUMFANG)*(float)umdrehungen/(float)zeit*3.6;
ms=float(RADUMFANG)*(float)umdrehungen/(float)zeit;
umin=umdrehungen*60000/zeit; }
else {
kph=0.0; //Définir zéro si aucun tour na été trouvé
umin = 0; } //Définir zéro si aucun tour na été trouvé
// ms = kph/3.6; //aus km/h mach m/s - kmh/3.6
ms2 = kph; //variable ms in ms2 global kopieren
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
alarm = map(val, 0, 1023, 0, 200); // scalieren der Potistellung (0-30m/s)200 = valeur maxi alarme vent
tft.setCursor(180,55);
//if(alarm < 10) tft.print("0"); // ein leerzeichen oder auch Zahl Nullf(zahl <10) print(" "); // ein leerzeichen oder auch Zahl Null
// tft.print(alarm);
tft.setCursor (10,20);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("ALARME VENT ");
tft.setTextColor (YELLOW,BLACK);
tft.setCursor (20,80);
tft.setTextSize (5);
tft.print (alarm);
tft.setTextColor (CYAN,BLACK);
tft.setTextSize (2);
tft.setCursor (160,90);
tft.print ("km/h");
//***************affichage remise a zero *************************************
// Réinitialiser lalarme LED si le vent est > 5 ms ou si le bouton de réinitialisation est enfoncé
// if (ms2 < 2 && digitalRead(ledalarm) == HIGH || digitalRead(resetmaxpin) == LOW)
tft.setTextColor(CYAN);
if (digitalRead(resetalarmpin) == LOW) {
digitalWrite(ledalarm, LOW);
tft.setCursor(190, 20);
tft.setTextSize(2);
tft.print ("remise a 0 ");
tft.setCursor(200, 60);
tft.setTextSize(5);
tft.print (" a 0");
}
tft.setCursor (270,20);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("VENT MAX ");
tft.setTextColor (CYAN,BLACK);
tft.setCursor (250,80);
tft.setTextSize (5);
dtostrf(msmax,5,2,buffer);
tft.print(buffer);
tft.setTextColor (CYAN,BLACK);
tft.setTextSize (2);
tft.setCursor (420,90);
tft.print ("km/h");
tft.setCursor (10,175);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("VENT ACTUEL ");
tft.setTextColor (ORANGE,BLACK);
tft.setCursor (7,230);
tft.setTextSize (5);
dtostrf(kph,2,2,buffer);
tft.print(buffer);
tft.setTextColor (CYAN,BLACK);
tft.setTextSize (2);
tft.setCursor (160,240);
tft.print ("km/h");
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
info_btn.press(down && info_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (info_btn.justReleased())
info_btn.drawButton();
if (menu_btn.justPressed()) {
menu_btn.drawButton(true);
currentPage = MENU;
}
break;
case PRESSION: // Menu PRESSION
if (currentPage != oldPage) drawSensorScreen();
tft.setCursor (10,20);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("Pression");
tft.setTextColor (YELLOW,BLACK);
tft.setCursor (7,70);
tft.setTextSize (5);
tft.print(P+12,2);
tft.setCursor (80,120);
tft.setTextSize (3);
tft.print ("hpa");
tft.setCursor (270,20);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print (" ALTITUDE");
tft.setTextColor (ORANGE,BLACK);
tft.setCursor (260,70);
tft.setTextSize (5);
tft.print (sdata7);
tft.setTextSize (2);
tft.print (" m");
tft.setCursor (7,165);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("Temperature ");
tft.setCursor (10,190);
tft.print (" Boitier ");
tft.setTextColor (BLUE,BLACK);
tft.setCursor (7,230);
tft.setTextSize (5);
tft.print (T,2);
tft.setTextColor (RED,BLACK);
tft.setTextSize (4);
tft.setTextColor (RED,BLACK);
tft.print ("C");
tft.setCursor (270,180);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("VENT Actuel ");
tft.setTextColor (GREEN,BLACK);
tft.setCursor (260,230);
tft.setTextSize (5);
dtostrf(kph,2,1,buffer);
tft.print(buffer);
tft.setCursor (400,240);
tft.setTextColor (CYAN,BLACK);
tft.setTextSize (2);
tft.print ("km/h");
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
info_btn.press(down && info_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (info_btn.justReleased())
info_btn.drawButton();
if (menu_btn.justPressed()) {
menu_btn.drawButton(true);
currentPage = MENU;
}
break;
case PISCINE:// Menu PISCINE
if (currentPage != oldPage) drawSensorScreen();
// float tmin,tmax,tnow,tlast,tminout,tmaxout,tnowout,tlastout,hmin,hmax,hnow,hlast;
tft.setCursor (7,20);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("PH");
tft.setTextColor(YELLOW,BLACK );
tft.setCursor (90,15);
tft.setTextSize (4);
tft.print(phValue,2);
tft.setCursor (7,70);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("TDS");
tft.setTextColor (GREEN,BLACK);
tft.setCursor (90,60);
tft.setTextSize (4);
tft.print (sensor::tds);
tft.setCursor (170,70);
tft.setTextSize (2);
tft.print ("ppm");
tft.setCursor (7,115);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("EC");
tft.setTextColor (BLUE,BLACK);
tft.setCursor (165,160);
tft.setTextSize (4);
tft.setCursor (90,110);
tft.println(sensor::ec, 2);
tft.setCursor (10,165);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("Temperature ");
tft.setCursor (10,190);
tft.print (" piscine ");
tft.setTextColor (RED,BLACK);
tft.setCursor (7,220);
tft.setTextSize (3);
tft.print ("MAX ");
tft.print (tmax);
tft.setTextSize (3);
tft.print (" C");
tft.setTextColor (YELLOW,BLACK);
tft.setCursor (7,255);
tft.setTextSize (3);
tft.print ("MIN ");
tft.print (tmin);
tft.setTextSize (3);
tft.print (" C");
tft.setCursor (270,15);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("Temperature ");
tft.setCursor (260,45);
tft.print (" exterieur ");
tft.setTextColor (RED,BLACK);
tft.setCursor (260,80);
tft.setTextSize (3);
tft.print ("MAX ");
tft.print (tmax1);
tft.setTextSize (3);
tft.print (" C");
tft.setTextColor (YELLOW,BLACK);
tft.setCursor (260,120);
tft.setTextSize (3);
tft.print ("MIN ");
tft.print (tmin1);
tft.setTextSize (3);
tft.print (" C");
tft.setCursor (270,170);
tft.setTextSize (3);
tft.setTextColor (WHITE,BLACK);
tft.print ("Humidite");
tft.setTextColor (RED,BLACK);
tft.setCursor (260,210);
tft.setTextSize (3);
tft.print ("MAX ");
tft.print (hmax);
tft.setTextSize (3);
tft.setTextColor(RED,BLACK);
tft.print (" %");
tft.setTextColor (YELLOW,BLACK);
tft.setCursor (260,240);
tft.setTextSize (3);
tft.print ("MIN ");
tft.print (hmin);
tft.setTextSize (3);
tft.setTextColor(RED,BLACK);
tft.print (" %");
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
info_btn.press(down && info_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (info_btn.justReleased())
info_btn.drawButton();
if (menu_btn.justPressed()) {
menu_btn.drawButton(true);
currentPage = MENU;
}
break;
}
if (oldPage == currentPage){
down = Touch_getXY();
}else{
down=false;
}
Serial.println(nodemcu.available());
if(nodemcu.available() == 0 )
{
cdata = cdata +","+sdata1+ ","+sdata2+ ","+sdata3 + "," +sdata4 + ","+sdata5+ ","+sdata6 + ","+sdata7 + ","+sdata8 + ","+sdata9 +","+sdata10
+","+sdata11 +","+sdata12 +","+sdata13 +","+sdata14 +","+sdata15 +","+sdata16 +","+sdata17 +","+sdata18 +","+sdata19 ;
nodemcu.println(cdata);
delay(10); // 100 milli seconds
cdata = "";
}
if ( nodemcu.available() > 0 )
{
data = nodemcu.parseInt();
delay(10);
Serial.println(data);
}
}
void readTdsQuick() {
DS18B20.requestTemperatures();
sensor::waterTemp = DS18B20.getTempCByIndex(0);
float rawEc = analogRead(pin::tds_sensor) * device::aref / 1024.0;
// read the analog value more stable by the median filtering algorithm, and convert to voltage value
float temperatureCoefficient = 1.0 + 0.02 * (sensor::waterTemp - 25.0);
// temperature compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));
sensor::ec = (rawEc / temperatureCoefficient) * sensor::ecCalibration; // temperature and calibration compensation
sensor::tds = (133.42 * pow(sensor::ec, 3) - 255.86 * sensor::ec * sensor::ec + 857.39 * sensor::ec) * 0.5; //convert voltage value to tds value
}
// get T, P, A readings from BMP180
bool measureBMP180(double& temp, double& pr, double& al)
{
char status;
double T,P,p0,a;
bool success = false;
// Start a temperature measurement:
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = bmp180.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Function returns 1 if successful, 0 if failure.
status = bmp180.getTemperature(T);
if (status != 0)
{
// save temp
temp = T; //température BMP180
// Start a pressure measurement:
// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = bmp180.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed pressure measurement:
// Note that the measurement is stored in the variable P.
// Note also that the function requires the previous temperature measurement (T).
// (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
// Function returns 1 if successful, 0 if failure.
status = bmp180.getPressure(P,T);
if (status != 0)
{
// save pressure
pr = P;
// calculate altitude using pressure at sea level
al = bmp180.altitude(P, 1018.25);
Serial.println("pression");
Serial.println(P+12);
Serial.println("temperature");
Serial.println(T);
Serial.println("altitude");
Serial.println(al);
delay (100);
sdata7 = al ;//Altitude
sdata8 = P+12 ;// pression
sdata9 = T ; // température boitier
// set flag
success = true;
}
}
}
}
return success;
}
void getDistance(long distance, int color){
float pHVol=(float)avgValue*5.0/1024/4.3;
float phValue = -5.70 * pHVol + 42.8;
phValue=14.2-phValue;
int x;
if(distance < 10 ) x=41;
else if((distance < 100) || (distance >= 1000)) x=28;
else x=19;
}
//***************affichage valeur potar*****************
void reedISR()
{
if (millis()-lastReedMillis>=5) // 25 ms correspond au maximum à 40 tours par seconde (pour les anémomètres populaires, le temps de rebondissement est suffisant)
{
reedCountSum++; // compter un tour de roue
reedMillisSum+=millis()-lastReedMillis; // Ajouter du temps
lastReedMillis=millis(); // Mémoriser le temps
}
}
void tachoAnzeige()
{
byte umdrehungen;
unsigned long zeit;
float kph, kilometer, ms;
char buffer[10];
noInterrupts(); // Bloquer les interrupts
umdrehungen=reedCountSum;// Réécrire la variable de comptage
reedCountSum=0; // Réinitialiser la variable de comptage à 0
zeit=reedMillisSum; // Réécrire le compteur de temps
reedMillisSum=0; // Réinitialiser le compteur de temps à 0
interrupts(); // Autoriser à nouveau les interruptions
gesamtUmdrehungen+= umdrehungen; // Cumuler tous les tours de roue
kilometer=(float)gesamtUmdrehungen*(float)RADUMFANG/1000000.0; // compteur kilométrique odomètre
if (umdrehungen>0){
kph=float(RADUMFANG)*(float)umdrehungen/(float)zeit*3.6;
ms=float(RADUMFANG)*(float)umdrehungen/(float)zeit;
umin=umdrehungen*60000/zeit; }
else {
kph=0.0; //Définir zéro si aucun tour na été trouvé
umin = 0; } //Définir zéro si aucun tour na été trouvé
// ms = kph/3.6; //aus km/h mach m/s - kmh/3.6
ms2 = kph; //variable ms in ms2 global kopieren
//enregistrer la valeur maximale
if (ms2 > msmax) {
msmax = ms2; }
// Serial.println(msmax);
}
/************************************************************************************
SCREENS DEFINTION
************************************************************************************/
//Menu d'accueil
void drawMenuScreen() {
tft.fillScreen(BLACK);
tft.setTextSize(4);
// Title
tft.setTextColor(WHITE, BLACK);
tft.setCursor( 70, 10);
tft.print("GESTION MAISON"); // Impression du titre
tft.drawLine(60, 62, tft.width() * 0.9, 62, CYAN); // Dessine la ligne sous le titre
// Dimmentions Button
page1_btn.initButton(&tft, tft.width() / 2., tft.height() / 2. - (1.*btnHeight + margin), 4 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "TEMPERATURES", 3);//cadre autour températures anemometre pression piscine
page2_btn.initButton(&tft, tft.width() / 2., tft.height() / 2., 4* btnWidth, btnHeight, WHITE, GREEN, BLACK, "ANEMOMETRE", 3);
page3_btn.initButton(&tft, tft.width() / 2., tft.height() / 2. + (1.*btnHeight + margin), 4 * btnWidth, btnHeight , WHITE, GREEN, BLACK, "PRESSION", 3);
page4_btn.initButton(&tft, tft.width() / 2., tft.height() / 2. + (2.1*btnHeight + margin), 4 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "PISCINE", 3);
page1_btn.drawButton(false);
page2_btn.drawButton(false);
page3_btn.drawButton(false);
page4_btn.drawButton(false);
//Cadre de bouton
tft.drawRoundRect(tft.width() / 3. - 1.5 * btnWidth, tft.height() / 2.3 - (1.5 * btnHeight + 2 * margin), 3.6 * btnWidth + btnWidth, 5.2 * btnHeight + 4 * margin, 10, ORANGE);// cadre autour des boutons
oldPage = currentPage;
}
//Menu bouton "menu"
void drawSensorScreen() {
tft.fillScreen(BLACK);
tft.drawLine(tft.width() / 2., 0, tft.width() / 2., tft.height(), WHITE);//ligne blanche verticale
tft.drawLine(0, tft.height() / 2., tft.width(), tft.height() / 2., WHITE);// ligne blanche horizontale
//updateTemp();
tft.setTextSize(1);
// bouton centré menu et info X,Y
menu_btn.initButton(&tft, tft.width() / 2. - btnWidth - margin , tft.height() - btnHeight / 2., btnWidth, btnHeight, WHITE, GREEN, BLACK, "MENU", 2);
info_btn.initButton(&tft, tft.width() / 2. + btnWidth + margin, tft.height() - btnHeight / 2., btnWidth, btnHeight, BLACK, BLACK, BLACK, "INFO", 2);
menu_btn.drawButton(false);
info_btn.drawButton(false);
oldPage = currentPage;
}
/************************************************************************************
UTILITY FUNCTION
*************************************************************************************/
void drawTextInRect(int x, int y, long temp, int tsize, unsigned int fColor, unsigned int bColor) {
/*int marg = 10;
char buf[12];
int nbChar = strlen(itoa(temp, buf, 10)) + 2;
if (bColor != 255) tft.fillRect(x - nbChar * 3 * tsize - marg, y - nbChar * 1 * tsize - marg, nbChar * 6 * tsize + 2 * marg, nbChar * 2 * tsize + 2 * marg, bColor);
tft.setTextSize(tsize);
tft.setTextColor(fColor, BLACK);
//tft.setCursor(x-strlen(*text)*3*tsize+marg, y+rheight/2.+marg);
tft.setCursor(x - nbChar * 3 * tsize, y - nbChar * 1 * tsize);
tft.print(temp);
//while(*text) tft.print(*text++);
tft.write(0xF7);
tft.setTextColor (RED,BLACK);
tft.print("C");*/
}
bool Touch_getXY(void)
{
p = ts.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH);
digitalWrite(XM, HIGH);
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
if (pressed) {
if (tft.width() <= tft.height()) { //Portrait
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
} else {
pixel_x = map(p.y, TS_TOP, TS_BOT, 0, tft.width());
pixel_y = map(p.x, TS_RT, TS_LEFT, 0, tft.height());
}
}
return pressed;
} |
Partager