Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //============================LIBRARY SERIAL============================
- #include <SoftwareSerial.h>
- SoftwareSerial mySerial(2, 3); // RX, TX
- //===============================sht30============================000
- //#include "cactus_io_SHT31.h"
- //#include<Wire.h>
- //cactus_io_SHT31 sensext(0x44);
- //===========================DHT===========================0
- #include "DHT.h"
- #define DHTPIN A0
- #define DHTTYPE DHT11
- DHT dht(DHTPIN, DHTTYPE);
- //===========================VARIABILE=========================00
- float temperature = 0.0f;
- float humidity = 0.0f;
- //==================================SETUP===============================000000
- void setup()
- {
- Serial.begin(9600);
- mySerial.begin(9600);
- dht.begin();
- //sensext.begin();
- }
- //====================================LOOP=================================
- void loop() {
- readSensor();
- sendhumidityToNextion();
- sendtemperatureToNextion();
- sendumibarToNextion();
- sendtempbarToNextion();
- readfixedtempFromNextion();
- readfixedtempFromNextion();
- delay(2000);
- }
- //=====================================SENSOR================================
- void readSensor()
- {
- humidity = dht.readHumidity();
- temperature = dht.readTemperature();
- // humidity = sensext.getHumidity();
- // temperature = sensext.getTemperature_C();
- }
- //===============================NEXTION BAR=========================================
- void sendumibarToNextion()
- {
- String command = "umibar.val="+String(int(humidity));
- mySerial.print(command);
- // Serial.println(command);
- endNextionCommand();
- }
- void sendtempbarToNextion()
- {
- String command = "tempbar.val="+String(int(temperature));
- mySerial.print(command);
- // Serial.println(command);
- endNextionCommand();
- }
- //====================================NEXTION VALUE=====================================
- void sendhumidityToNextion()
- {
- String command = "humidity.txt=\""+String(humidity)+"\"";
- mySerial.print(command);
- // Serial.println(command);
- endNextionCommand();
- }
- void sendtemperatureToNextion()
- {
- String command = "temperature.txt=\""+String(temperature)+"\"";
- mySerial.print(command);
- //Serial.println(command);
- endNextionCommand();
- }
- //===============================Lettura di quello che manda il display ===================================0
- void readfixedtempFromNextion()
- {
- String mess=""; //stringa completa
- String fixedtemp="fixedtemp=" ;
- String fixedumid="fixedumid=";
- char leggi;
- int i;
- if (mySerial.available()>0) // la seriale invia qualcosa tramite il pulsante invia del display
- {
- while(mySerial.available()>0){ // fin quando la seriale è aperta
- leggi=mySerial.read();//scrivi nella char leggi quello che leggi dal dal display
- mess= mess + leggi;
- if(mess == fixedtemp ){
- Serial.print(mess);
- Serial.print("\n");
- mess="";
- leggi=mySerial.read();
- mess= mess + int(leggi);
- Serial.print(mess);
- Serial.print("\n");
- // delay(500);
- }
- if(mess == fixedumid ){
- Serial.print(mess);
- Serial.print("\n");
- mess="";
- leggi=mySerial.read();
- mess= mess + int(leggi);
- Serial.print(mess);
- Serial.print("\n");
- // delay(500);
- }
- }
- }
- }
- //====================================END TRASMITION NEXTION============================00
- void endNextionCommand()
- {
- mySerial.write(0xff);
- mySerial.write(0xff);
- mySerial.write(0xff);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement