Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1.  
  2.  
  3. //============================LIBRARY SERIAL============================
  4.  
  5. #include <SoftwareSerial.h>
  6. SoftwareSerial mySerial(2, 3); // RX, TX
  7.  
  8. //===============================sht30============================000
  9. //#include "cactus_io_SHT31.h"
  10. //#include<Wire.h>
  11. //cactus_io_SHT31 sensext(0x44);
  12. //===========================DHT===========================0
  13.  
  14. #include "DHT.h"
  15.  
  16. #define DHTPIN A0
  17. #define DHTTYPE DHT11
  18.  
  19. DHT dht(DHTPIN, DHTTYPE);
  20. //===========================VARIABILE=========================00
  21.  
  22. float temperature = 0.0f;
  23. float humidity = 0.0f;
  24.  
  25.  
  26. //==================================SETUP===============================000000
  27. void setup()
  28. {
  29. Serial.begin(9600);
  30. mySerial.begin(9600);
  31. dht.begin();
  32. //sensext.begin();
  33. }
  34. //====================================LOOP=================================
  35.  
  36.  
  37. void loop() {
  38.  
  39.  
  40. readSensor();
  41. sendhumidityToNextion();
  42. sendtemperatureToNextion();
  43. sendumibarToNextion();
  44. sendtempbarToNextion();
  45. readfixedtempFromNextion();
  46. readfixedtempFromNextion();
  47. delay(2000);
  48. }
  49. //=====================================SENSOR================================
  50. void readSensor()
  51. {
  52. humidity = dht.readHumidity();
  53. temperature = dht.readTemperature();
  54.  
  55. // humidity = sensext.getHumidity();
  56. // temperature = sensext.getTemperature_C();
  57. }
  58. //===============================NEXTION BAR=========================================
  59.  
  60. void sendumibarToNextion()
  61. {
  62. String command = "umibar.val="+String(int(humidity));
  63. mySerial.print(command);
  64. // Serial.println(command);
  65. endNextionCommand();
  66. }
  67.  
  68. void sendtempbarToNextion()
  69. {
  70. String command = "tempbar.val="+String(int(temperature));
  71. mySerial.print(command);
  72. // Serial.println(command);
  73.  
  74. endNextionCommand();
  75. }
  76. //====================================NEXTION VALUE=====================================
  77. void sendhumidityToNextion()
  78. {
  79. String command = "humidity.txt=\""+String(humidity)+"\"";
  80.  
  81. mySerial.print(command);
  82. // Serial.println(command);
  83. endNextionCommand();
  84. }
  85.  
  86. void sendtemperatureToNextion()
  87. {
  88. String command = "temperature.txt=\""+String(temperature)+"\"";
  89. mySerial.print(command);
  90. //Serial.println(command);
  91.  
  92. endNextionCommand();
  93. }
  94. //===============================Lettura di quello che manda il display ===================================0
  95.  
  96. void readfixedtempFromNextion()
  97.  
  98. {
  99. String mess=""; //stringa completa
  100. String fixedtemp="fixedtemp=" ;
  101. String fixedumid="fixedumid=";
  102. char leggi;
  103. int i;
  104. if (mySerial.available()>0) // la seriale invia qualcosa tramite il pulsante invia del display
  105. {
  106. while(mySerial.available()>0){ // fin quando la seriale è aperta
  107.  
  108. leggi=mySerial.read();//scrivi nella char leggi quello che leggi dal dal display
  109.  
  110. mess= mess + leggi;
  111.  
  112.  
  113. if(mess == fixedtemp ){
  114. Serial.print(mess);
  115. Serial.print("\n");
  116.  
  117. mess="";
  118. leggi=mySerial.read();
  119. mess= mess + int(leggi);
  120. Serial.print(mess);
  121. Serial.print("\n");
  122. // delay(500);
  123. }
  124. if(mess == fixedumid ){
  125. Serial.print(mess);
  126. Serial.print("\n");
  127.  
  128. mess="";
  129. leggi=mySerial.read();
  130. mess= mess + int(leggi);
  131. Serial.print(mess);
  132. Serial.print("\n");
  133. // delay(500);
  134. }
  135.  
  136. }
  137. }
  138. }
  139.  
  140. //====================================END TRASMITION NEXTION============================00
  141. void endNextionCommand()
  142. {
  143. mySerial.write(0xff);
  144. mySerial.write(0xff);
  145. mySerial.write(0xff);
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement