smort

fermctrl

Apr 27th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.15 KB | None | 0 0
  1. // Include the libraries we need
  2. #define BLYNK_PRINT Serial // Defines the object that is used for printing
  3. //#define BLYNK_DEBUG        // Optional, this enables more detailed prints
  4.  
  5. #define ONE_WIRE_BUS_BEER D1
  6. #define ONE_WIRE_BUS_AMBIENT D2
  7.  
  8. #include <OneWire.h>
  9. #include <DallasTemperature.h>
  10. #include <ESP8266WiFi.h>
  11. #include <BlynkSimpleEsp8266.h>
  12. #include <ESP8266HTTPClient.h>
  13. #include <ArduinoJson.h>
  14. #include <TimeLib.h>
  15. #include <WidgetRTC.h>
  16. #include "FS.h"
  17.  
  18. const char* device = "F1";
  19. const char* address = "http://192.168.88.88:1880/F1";
  20. float tempC;
  21. float ambient;
  22. float pressure;
  23. float Tsp;
  24. float Thyst;
  25. float Psp;
  26. float Physt;
  27. int Pzero;
  28. int bitsprbar = 1;
  29. float coolthreshold;
  30. bool syncneeded;
  31. int temp_steptime[10];
  32. float temp_steptemp[10];
  33. float temp_stepramp[10];
  34. const char* fermnames[10];
  35. String beername;
  36. int stepsize;
  37. int nextsteptime;
  38. int nextramptime;
  39. int stepcounter;
  40. int fermenting;
  41. int currenttime;
  42. String startTimeDate;
  43. time_t starttime;
  44. const char pressdelay = 1; //seconds
  45. int lastpress;
  46. int conversiontime = 2000;
  47. const int resolution = 11;
  48. unsigned long lastTime;
  49. const char auth[] = "";
  50. const char ssid[] = "";
  51. const char pass[] = "";
  52.  
  53. HTTPClient http; //HTTPClient used in getdata
  54.  
  55. WidgetLED ledheat(V0);
  56. WidgetLED ledcool(V13);
  57. WidgetLED ledpressure(V11);
  58. WidgetTerminal terminal(V69);
  59. WidgetLCD lcd(V68);
  60. WidgetRTC rtc;
  61.  
  62.  
  63. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  64. OneWire oneWire_beer(ONE_WIRE_BUS_BEER);
  65. OneWire oneWire_ambient(ONE_WIRE_BUS_AMBIENT);
  66.  
  67. // Pass our oneWire reference to DS18B20 lib.
  68. DallasTemperature sensor_beer(&oneWire_beer);
  69. DallasTemperature sensor_ambient(&oneWire_ambient);
  70.  
  71.  
  72. BlynkTimer timer;
  73.  
  74. BLYNK_CONNECTED() {
  75.   Blynk.syncAll();
  76. }
  77.  
  78. BLYNK_WRITE(V3) {                           // Value from Blynk slider or numeric input
  79.   Tsp = param.asFloat();   // assigning incoming value from pin V1 to a variable
  80. }
  81. BLYNK_WRITE(V10) {                           // Value from Blynk slider or numeric input
  82.   Psp = param.asFloat();   // assigning incoming value from pin V1 to a variable
  83. }
  84. BLYNK_WRITE(V5) {                           // Value from Blynk slider or numeric input
  85.   Thyst = param.asFloat(); // assigning incoming value from pin V2 to a variable
  86. }
  87. BLYNK_WRITE(V6) {                           // Value from Blynk slider or numeric input
  88.   Physt = param.asFloat(); // assigning incoming value from pin V2 to a variable
  89. }
  90. BLYNK_WRITE(V7) {                           // Value from Blynk slider or numeric input
  91.   Pzero = param.asInt(); // assigning incoming value from pin V2 to a variable
  92. }
  93. BLYNK_WRITE(V8) {                           // Value from Blynk slider or numeric input
  94.   bitsprbar = param.asInt(); // assigning incoming value from pin V2 to a variable
  95. }
  96. BLYNK_WRITE(V14) {                           // Value from Blynk slider or numeric input
  97.   coolthreshold = param.asFloat(); // assigning incoming value from pin V2 to a variable
  98. }
  99.  
  100. BLYNK_WRITE(V51) {
  101.   int loadbutton = param.asInt();
  102.   if (loadbutton == 1 && currenttime - lastpress >= pressdelay) {
  103.     lastpress = now();
  104.     getdata();
  105.     loadbutton = 0;
  106.   }
  107. }
  108.  
  109. BLYNK_WRITE(V52) {
  110.   beername = param[0].asString();
  111.   stepsize = param[1].asInt();
  112. }
  113.  
  114. BLYNK_WRITE(V54) {
  115.   int clearbutton = param.asInt();
  116.   if (clearbutton == 1 && currenttime - lastpress >= pressdelay && syncneeded == false) {
  117.     clearbutton = 0;
  118.     lastpress = now();
  119.     cleardata();
  120.   }
  121. }
  122.  
  123. BLYNK_WRITE(V55) {
  124.   int startbutton = param.asInt();
  125.   if (startbutton == 1 && (currenttime - lastpress >= pressdelay) && syncneeded == false) {
  126.     lastpress = now();
  127.     startferment();
  128.   }
  129. }
  130. BLYNK_WRITE(V56) {
  131.   startTimeDate  = param.asString();
  132. }
  133.  
  134. BLYNK_WRITE(V110) {
  135.   stepcounter = param.asInt();
  136. }
  137.  
  138. BLYNK_WRITE(V111) {
  139.   fermenting = param.asInt();
  140. }
  141.  
  142. BLYNK_WRITE(V120) {
  143.   nextsteptime  = param.asInt();
  144. }
  145. BLYNK_WRITE(V122) {
  146.   starttime  = param.asInt();
  147. }
  148. BLYNK_WRITE(V123) {
  149.   nextramptime  = param.asInt();
  150. }
  151. void reportpressurevalue() {
  152.   Blynk.virtualWrite(V9, pressure);
  153.   Blynk.virtualWrite(V10, Psp);
  154. }
  155.  
  156. void reporttime() {     //reports reading to blynk every time reportvalue gets called
  157.   currenttime = now();
  158.   Blynk.virtualWrite(V121, currenttime);
  159.  
  160.   if (syncneeded == true) {
  161.     Blynk.virtualWrite(V52, beername, stepsize);
  162.     byte atstep = stepsize - 1;
  163.     terminal.clear();
  164.  
  165.     if (atstep >= 0) {
  166.       // String fermname = String(fermnames[0]);
  167.       String s = (String(fermnames[0]) + "  @   " + String(temp_steptemp[0]) + "°C" + " for " + String(temp_steptime[0]) + " days");
  168.       terminal.println(s);
  169.     }
  170.     if (atstep >= 1) {
  171.       String s = (String(fermnames[1]) + "  @   " + String(temp_steptemp[1]) + "°C" + " for " + String(temp_steptime[1]) + " days");
  172.       terminal.println(s);
  173.       // terminal.flush();
  174.     }
  175.     if (atstep >= 2) {
  176.       String s = (String(fermnames[2]) + "  @   " + String(temp_steptemp[2]) + "°C" + " for " + String(temp_steptime[2]) + " days");
  177.       terminal.println(s);
  178.       //terminal.flush();
  179.     }
  180.     if (atstep >= 3) {
  181.       String s = (String(fermnames[3]) + "  @   " + String(temp_steptemp[3]) + "°C" + " for " + String(temp_steptime[3]) + " days");
  182.       terminal.println(s);
  183.       // terminal.flush();
  184.     }
  185.     if (atstep >= 4) {
  186.       String s = (String(fermnames[4]) + "  @   " + String(temp_steptemp[4]) + "°C" + " for " + String(temp_steptime[4]) + " days");
  187.       terminal.println(s);
  188.       // terminal.flush();
  189.     }
  190.     if (atstep >= 5) {
  191.       String s = (String(fermnames[5]) + "  @   " + String(temp_steptemp[5]) + "°C" + " for " + String(temp_steptime[5]) + " days");
  192.       terminal.println(s);
  193.       // terminal.flush();
  194.     }
  195.     if (atstep >= 6) {
  196.       String s = (String(fermnames[6]) + "  @   " + String(temp_steptemp[6]) + "°C" + " for " + String(temp_steptime[6]) + " days");
  197.       terminal.println(s);
  198.       // terminal.flush();
  199.     }
  200.     if (atstep >= 7) {
  201.       String s = (String(fermnames[7]) + "  @   " + String(temp_steptemp[7]) + "°C" + " for " + String(temp_steptime[7]) + " days");
  202.       terminal.println(s);
  203.       //  terminal.flush();
  204.     }
  205.     if (atstep >= 8) {
  206.       String s = (String(fermnames[8]) + "  @   " + String(temp_steptemp[8]) + "°C" + " for " + String(temp_steptime[8]) + " days");
  207.       terminal.println(s);
  208.       // terminal.flush();
  209.     }
  210.     if (atstep >= 9) {
  211.       String s = (String(fermnames[9]) + "  @   " + String(temp_steptemp[9]) + "°C" + " for " + String(temp_steptime[9]) + " days");
  212.       terminal.println(s);
  213.       //terminal.flush();
  214.     }
  215.     terminal.flush();
  216.     syncneeded = false;
  217.     delay(2000);
  218.   }
  219. }
  220.  
  221. void getdata() { // Opens a http GET to Node Red, deserialize the JSON and save the arrays in SPIFFS.
  222.   Serial.println("getting data");
  223.  
  224.   if (WiFi.status() == WL_CONNECTED)
  225.   {
  226.     http.begin(address);
  227.     int httpCode = http.GET();
  228.  
  229.     if (httpCode > 0)  {
  230.       const size_t capacity = 14 * JSON_ARRAY_SIZE(0) + 6 * JSON_ARRAY_SIZE(1) + 4 * JSON_ARRAY_SIZE(2) + 3 * JSON_ARRAY_SIZE(3) + JSON_ARRAY_SIZE(4) + JSON_ARRAY_SIZE(10) + 18 * JSON_OBJECT_SIZE(2) + 10 * JSON_OBJECT_SIZE(3) + 3 * JSON_OBJECT_SIZE(4) + 4 * JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + 13 * JSON_OBJECT_SIZE(7) + JSON_OBJECT_SIZE(8) + 3 * JSON_OBJECT_SIZE(9) + 6 * JSON_OBJECT_SIZE(12) + JSON_OBJECT_SIZE(13) + 2 * JSON_OBJECT_SIZE(14) + 2 * JSON_OBJECT_SIZE(15) + 3 * JSON_OBJECT_SIZE(16) + 4 * JSON_OBJECT_SIZE(19) + JSON_OBJECT_SIZE(22) + 4 * JSON_OBJECT_SIZE(23) + JSON_OBJECT_SIZE(30) + JSON_OBJECT_SIZE(39) + JSON_OBJECT_SIZE(63) + 10740;
  231.       DynamicJsonDocument doc(capacity);
  232.  
  233.       deserializeJson(doc, http.getString());
  234.  
  235.       const char* beer = doc["recipe"]["name"];
  236.       beername = String(beer);
  237.       Serial.println(beer);
  238.  
  239.       JsonArray steps_repo = doc["recipe"]["fermentation"]["steps"];
  240.  
  241.       stepsize = steps_repo.size();
  242.       int i = 0;
  243.       for (JsonObject repo : steps_repo) {
  244.         temp_steptime[i] = repo["stepTime"].as<int>();
  245.         i++;
  246.         //Serial.println(temp_steptime[i]);
  247.       }
  248.      
  249.            // open file for writing steptime
  250.       File f = SPIFFS.open("/steptime.txt", "w");
  251.       if (!f) {
  252.         Serial.println("file open failed");
  253.       }
  254.       Serial.println("====== Writing to SPIFFS file =========");
  255.       // write 10 strings to file
  256.       for (byte z = 0; z < stepsize; z++) {
  257.         f.println(temp_steptime[z]);
  258.         Serial.print("written:... ");
  259.         Serial.println(temp_steptime[z]);
  260.       }
  261.       f.close();
  262.  
  263.       i = 0;
  264.       for (JsonObject repo : steps_repo) {
  265.         temp_steptemp[i] = repo["stepTemp"].as<float>();
  266.         i++;
  267.         //Serial.println(temp_steptemp[i]);
  268.       }
  269.  
  270.       // open file for writing steptemp
  271.       File a = SPIFFS.open("/steptemp.txt", "w");
  272.       if (!a) {
  273.         Serial.println("file open failed");
  274.       }
  275.       Serial.println("====== Writing to SPIFFS file =========");
  276.       // write 10 strings to file
  277.       for (byte z = 0; z < stepsize; z++) {
  278.         a.println(temp_steptemp[z]);
  279.         Serial.print("written:... ");
  280.         Serial.println(temp_steptemp[z]);
  281.       }
  282.       a.close();
  283.  
  284.  
  285.       i = 0;
  286.       for (JsonObject repo : steps_repo) {
  287.         temp_stepramp[i] = repo["ramp"].as<int>();
  288.         i++;
  289.         //Serial.println(temp_stepramp[i]);
  290.       }
  291.  
  292.       // open file for writing stepramp
  293.       File c = SPIFFS.open("/stepramp.txt", "w");
  294.       if (!c) {
  295.         Serial.println("file open failed");
  296.       }
  297.       Serial.println("====== Writing to SPIFFS file =========");
  298.       // write 10 strings to file
  299.       for (byte z = 0; z < stepsize; z++) {
  300.         c.println(temp_stepramp[z]);
  301.         Serial.print("written:... ");
  302.         Serial.println(temp_stepramp[z]);
  303.       }
  304.       c.close();
  305.  
  306.  
  307.       i = 0;
  308.       for (JsonObject repo : steps_repo) {
  309.         fermnames[i] = repo["type"].as<char *>();
  310.         i++;
  311.         //Serial.println(fermnames[i]);
  312.       }
  313.  
  314.       // open file for writing steptemp
  315.       File d = SPIFFS.open("/fermnames.txt", "w");
  316.       if (!d) {
  317.         Serial.println("file open failed");
  318.       }
  319.       Serial.println("====== Writing to SPIFFS file =========");
  320.       // write 10 strings to file
  321.       for (byte z = 0; z < stepsize; z++) {
  322.         d.println(fermnames[z]);
  323.         Serial.print("written:... ");
  324.         Serial.println(fermnames[z]);
  325.       }
  326.       d.close();
  327.  
  328.       syncneeded = true;
  329.       Serial.println("OK");
  330.     }
  331.     http.end(); //Close connection
  332.  
  333.   }
  334. }
  335.  
  336. void startferment() { //when startbutton is pressed
  337.   if (syncneeded == false) {
  338.     fermenting = 1;
  339.     starttime = now();
  340.     String startTimeDate = String(day(starttime)) + "." + month(starttime) + "." + year(starttime) + " " + hour(starttime) + ":" + minute(starttime);
  341.     stepcounter = 0;
  342.     nextsteptime = starttime + (temp_steptime[0] * 86400);
  343.     nextramptime = nextsteptime - (temp_stepramp[0] * 86400);
  344.     Tsp = temp_steptemp[stepcounter];
  345.     String s = "Step" + String(stepcounter + 1) + " @ " + String(temp_steptemp[stepcounter]) + "°C";
  346.     lcd.clear();
  347.     lcd.print(0, 0, "Fermenting");
  348.     lcd.print(0, 1, s);
  349.     Blynk.virtualWrite(V3, Tsp);
  350.     Blynk.virtualWrite(V56, startTimeDate);
  351.     Blynk.virtualWrite(V111, fermenting);
  352.     Blynk.virtualWrite(V120, nextsteptime);
  353.     Blynk.virtualWrite(V122, starttime);
  354.     Blynk.virtualWrite(V123, nextramptime);
  355.   }
  356. }
  357.  
  358. void cleardata() { // when clearbutton is pressed
  359.   if (syncneeded == false) {
  360.     fermenting = 0;
  361.     stepcounter = 0;
  362.     nextsteptime = 1666666666;
  363.     nextramptime = 1666666666;
  364.     terminal.clear();
  365.     lcd.clear();
  366.     lcd.print(0, 0, "Stopped");
  367.     Blynk.virtualWrite(V56, "x");
  368.     Blynk.virtualWrite(V110, stepcounter);
  369.     Blynk.virtualWrite(V111, fermenting);
  370.     Blynk.virtualWrite(V120, nextsteptime);
  371.     Blynk.virtualWrite(V123, nextramptime);
  372.     Serial.println("clear");
  373.   }
  374. }
  375.  
  376. void newstep() { //when its time to go to next step
  377.   if (syncneeded == false) {
  378.     stepcounter += 1;
  379.     if (stepcounter >= (stepsize - 1) ) {
  380.       stepcounter = (stepsize - 1);
  381.     }
  382.     Tsp = temp_steptemp[stepcounter];
  383.     int totalsteptime = 0;
  384.     for (int i = 0; i <= stepcounter; i++) {
  385.       totalsteptime += temp_steptime[i];
  386.     }
  387.     nextsteptime = starttime + (totalsteptime * 86400);
  388.     nextramptime = nextsteptime - (temp_stepramp[stepcounter] * 86400);
  389.     String s = "step" + String(stepcounter + 1) + " @ " + String(temp_steptemp[stepcounter]) + "°C";
  390.     lcd.clear();
  391.     lcd.print(0, 0, "Fermenting");
  392.     lcd.print(0, 1, s);
  393.     Blynk.virtualWrite(V3, Tsp);
  394.     Blynk.virtualWrite(V110, stepcounter);
  395.     Blynk.virtualWrite(V120, nextsteptime);
  396.     Blynk.virtualWrite(V123, nextramptime);
  397.   }
  398. }
  399.  
  400. void ramp() { // calculate ramp setpoint
  401.   if (currenttime > nextramptime && fermenting == 1) {
  402.     int next = stepcounter + 1;
  403.     float a = (currenttime - nextramptime);
  404.     float c = (nextsteptime - nextramptime);
  405.     float rampfactor = a / c;
  406.     Tsp = (rampfactor * (temp_steptemp[next] - temp_steptemp[stepcounter]) + temp_steptemp[stepcounter]);
  407.     String s = String(temp_steptemp[stepcounter + 1]) + "-> " + String(temp_steptemp[next + 1]) + "°C";
  408.     String t = "Ramping->step" + String(next);
  409.     lcd.clear();
  410.     lcd.print(0, 0, t);
  411.     lcd.print(0, 1, s);
  412.     Blynk.virtualWrite(V3, Tsp);
  413.   }
  414. }
  415.  
  416. void readpressuresensor() { //read pressure sensor
  417.   if (syncneeded == false) {//
  418.     // read the value from the analog sensor:
  419.     int currentSensorValue = analogRead(A0);
  420.     //map readings from purgepot to purgetime
  421.     pressure = ((currentSensorValue - Pzero) / bitsprbar);
  422.     // Serial.print("analog: "); Serial.println(currentSensorValue);
  423.   }
  424. }
  425. void readtempsensor() { //read tempsensors
  426.   tempC = sensor_beer.getTempCByIndex(0);
  427.   ambient = sensor_ambient.getTempCByIndex(0);
  428.   sensor_ambient.requestTemperatures();
  429.   sensor_beer.requestTemperatures();
  430.   Blynk.virtualWrite(V1, tempC);
  431.   Blynk.virtualWrite(V12, ambient);
  432. }
  433.  
  434. void tcp() { //send logdata to Node Red
  435.   const uint16_t port = 8881;          // port to use
  436.   const char * host = "192.168.88.88"; // address of server
  437.  
  438.   // Use WiFiClient class to create TCP connections
  439.   WiFiClient client;
  440.  
  441.   if (!client.connect(host, port)) {
  442.     Serial.println("connection failed");
  443.     Serial.println("wait 5 sec...");
  444.     loop();
  445.   }
  446.   const size_t capacity = JSON_OBJECT_SIZE(12);
  447.  
  448.   DynamicJsonDocument doc(capacity);
  449.  
  450.   JsonObject object = doc.to<JsonObject>();
  451.   doc["name"] = device;
  452.   doc["temp"] = tempC;
  453.   //doc["aux_temp"] = 15.61;
  454.   doc["ext_temp"] = ambient;
  455.   doc["temp_unit"] = "C";
  456.   //doc["gravity"] = 1.042;
  457.   //doc["gravity_unit"] = "SG";
  458.   doc["pressure"] = pressure;
  459.   doc["pressure_unit"] = "BAR";
  460.   //doc["ph"] = 4.12;
  461.   //doc["comment"] = "Hello World";
  462.   doc["beer"] = beername;
  463.  
  464.   serializeJsonPretty(object, client);
  465.   Serial.println("TCP sent");
  466.  
  467.   client.stop();
  468. }
  469.  
  470. void setup()
  471. {
  472.   // start serial port
  473.   Serial.begin(9600);
  474.   Blynk.begin(auth, ssid, pass);
  475.   rtc.begin();
  476.   currenttime = now();
  477.   Blynk.syncAll();
  478.  
  479.   Serial.println("Start SPIFFS....");
  480.   SPIFFS.begin();
  481.   Serial.println("Started");
  482.   delay(3000);
  483.   // Next lines have to be done ONLY ONCE!!!!!When SPIFFS is formatted ONCE you can comment these lines out!!
  484.   //Serial.println("Please wait 30 secs for SPIFFS to be formatted");
  485.   // SPIFFS.format();
  486.  // Serial.println("Spiffs formatted");
  487.  
  488.   File f = SPIFFS.open("/steptime.txt", "r");
  489.   if (!f) {
  490.     Serial.println("file open failed");
  491.   }  Serial.println("====== Reading steptime from SPIFFS file =======");
  492.  
  493.   for (int i = 0; i < stepsize; i++) {
  494.     int reading = f.parseInt();
  495.     temp_steptime[i] = reading;
  496.     Serial.print("Reading...  ");
  497.     Serial.println(temp_steptime[i]);
  498.   }
  499.   f.close();
  500.  
  501.   File a = SPIFFS.open("/steptemp.txt", "r");
  502.   if (!a) {
  503.     Serial.println("file open failed");
  504.   }  Serial.println("====== Reading steptemp from SPIFFS file =======");
  505.  
  506.   for (int i = 0; i < stepsize; i++) {
  507.     float reading = a.parseFloat();
  508.     temp_steptemp[i] = reading;
  509.     Serial.print("Reading...  ");
  510.     Serial.println(temp_steptemp[i]);
  511.   }
  512.   a.close();
  513.  
  514.   File c = SPIFFS.open("/stepramp.txt", "r");
  515.   if (!c) {
  516.     Serial.println("file open failed");
  517.   }  Serial.println("====== Reading stepramp from SPIFFS file =======");
  518.  
  519.   for (int i = 0; i < stepsize; i++) {
  520.     float reading = c.parseFloat();
  521.     temp_stepramp[i] = reading;
  522.     Serial.print("Reading...  ");
  523.     Serial.println(temp_stepramp[i]);
  524.   }
  525.   c.close();
  526.  
  527.   File d = SPIFFS.open("/fermnames.txt", "r");
  528.   if (!d) {
  529.     Serial.println("file open failed");
  530.   }  Serial.println("====== Reading fermnames from SPIFFS file =======");
  531.   for (byte i = 0; i < stepsize; i++)   {
  532.     String linefromfile = d.readStringUntil('\n');
  533.     const char *stringtochar = linefromfile.c_str();
  534.     fermnames[i] = stringtochar;
  535.     Serial.print("Reading...  ");
  536.     Serial.println(fermnames[i]);
  537.   }
  538.   d.close();
  539.  
  540.  
  541.   sensor_beer.begin();
  542.   sensor_ambient.begin();
  543.   sensor_beer.setResolution(resolution);
  544.   sensor_ambient.setResolution(resolution);
  545.   sensor_ambient.requestTemperatures();
  546.   sensor_beer.requestTemperatures();
  547.   sensor_beer.setWaitForConversion(false);
  548.   sensor_ambient.setWaitForConversion(false);
  549.  
  550.  
  551.  
  552.   timer.setInterval(2000L, reporttime);
  553.   timer.setInterval(5000L, reportpressurevalue);
  554.   timer.setInterval(500L, readpressuresensor);
  555.   timer.setInterval(10000L, readtempsensor);
  556.   timer.setInterval(60000L, ramp);
  557.   timer.setInterval(30000L, tcp);
  558.  
  559. }
  560.  
  561. void loop() {
  562.  
  563.   Blynk.run();
  564.   timer.run(); // Initiates BlynkTimer
  565.  
  566.  
  567.   // setpoint increase
  568.   if (now() > nextsteptime) {
  569.     if (fermenting == 1); {
  570.       newstep();
  571.     }
  572.   }
  573.  
  574.   //heat
  575.   if ((tempC <= Tsp - Thyst) && (ambient < Tsp)) {
  576.     ledheat.on();
  577.   }
  578.   else if (tempC >= Tsp) {
  579.     ledheat.off();
  580.   }
  581.  
  582.   //cool
  583.   if ((tempC >= Tsp + Thyst) && ((ambient + coolthreshold) > Tsp))  {
  584.     ledcool.on();
  585.   }
  586.   else if (tempC <= Tsp) {
  587.     ledcool.off();
  588.   }
  589.  
  590.   //pressure
  591.   if (pressure >= Psp - Physt) {
  592.     ledpressure.on();
  593.   }
  594.   else if (pressure <= Psp) {
  595.     ledpressure.off();
  596.   }
  597.  
  598. }
Advertisement
Add Comment
Please, Sign In to add comment