FunctionsAndClasses

_TH_sensor


  1. // www.officinecibernetiche.net
  2. /*************************************
  3.  *   temperature & humidity sensor   *
  4.  *   read it every 1 second ...      *
  5.  *   0-50°C 20-80% humidity          *
  6.  *************************************/
  7. void temp_hum()
  8. {
  9.   bar.setLed(4, 1); delay(1000);
  10.  
  11.   logHandler("temp_hum", 0);
  12.   char t[10] = {};  // se char* restarta alla chiamata
  13.   char h[10] = {};
  14.  
  15.   delay(dht.getMinimumSamplingPeriod());
  16.  
  17.   float temperature = dht.getTemperature();
  18.   dtostrf(temperature, 2, 1, t);
  19.   temper = t;  // char* = char array
  20.  
  21.   float humidity = dht.getHumidity();
  22.   dtostrf(humidity, 2, 1, h);
  23.   hum = h;
  24.  
  25.   const char* dhtStatus = dht.getStatusString();
  26.  
  27.   if (strncmp(dhtStatus, "OK", 2) == 0) {
  28.     dhtStat = "Valid";
  29.   } else {
  30.     dhtStat = "notValid";
  31.   }
  32.  
  33.   ledAlarmcode = 1;
  34.   if (temperature > 28) {
  35.     ledAlarmcode = 1;
  36.   } else if (temperature > 30) {
  37.     ledAlarmcode = 2;
  38.   } else if (temperature > 35) {
  39.     ledAlarmcode = 3;
  40.   }
  41.   switchonLedAlarm(ledAlarmcode);
  42.  
  43.   String messag;
  44.   messag += "Hum:"; messag += hum; messag += "% Temp:"; messag += temper; messag += "^C - "; messag += dhtStat;
  45.   int str_len = messag.length() + 1;
  46.   messag.toCharArray(TH_char_array, 31);
  47.  
  48.   messag = "";
  49.   messag += temper;
  50.   messag.toCharArray(Temperatura, 3);
  51.  
  52.   messag = "";
  53.   messag += hum;
  54.   messag.toCharArray(Umidita, 3);
  55.  
  56.   logEvent2SD(TH_char_array);
  57.   logHandler(TH_char_array, 0);
  58.  
  59.   bar.setLed(9, 0);
  60.   return;
  61. }
  62.  
  63.  
  64. // T-H sensor setup
  65. void dht11_Setup()
  66. {
  67.   Serial.println("Init Temperature sensor");
  68.   displayMessages(-1, -1, "4. Temp sensor");
  69.   logHandler("Initializing Temperature sensor", 1);
  70.   //delay(1000);
  71.   delay(dht.getMinimumSamplingPeriod());
  72.   dht.setup(8);  // data on pin 8
  73. }
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki