-// temps entre actualitzacions de els elements
-// [lm35_1, lm35_2, ldr_1]
 #include <Wire.h>
 #include <SFE_BMP180.h>
+#include "DHT.h"
 
 #define count(x) sizeof(x)/sizeof(unsigned long)
 #define groundPin A0
-#define ALTITUDE 570
+
+
+#define ALTITUDE 570 // We need it for the barometric pressure calculus
 
 #define BMP180T 0   // Temperature
 #define BMP180P 1   // Pressure
+#define DHT22T  2   // Temperature
+#define DHT22H  3   // Humidity
+#define DHT22HI 4   // Heat Index
 
-#define NOTUSED -1  // For BMP180 sensor.
+#define NOTUSED -1  // For BMP180/DHT22 sensor.
+
+#define DHTTYPE DHT22
+#define DHTPIN  4
 
 SFE_BMP180 pressure;
+DHT dht(DHTPIN, DHTTYPE);
 
-int types[] = {BMP180T,BMP180P};
-unsigned long lastUpdate[] = {0,0};
-unsigned long updateTimes[] = {30000,60000};
-int pins[] = {NOTUSED,NOTUSED};
+int types[] = {BMP180T,BMP180P,DHT22T,DHT22H,DHT22HI};
+unsigned long lastUpdate[] = {0,0,0,0,0};
+unsigned long updateTimes[] = {30000,60000,30000,30000,60000};
+int pins[] = {NOTUSED,NOTUSED,NOTUSED,NOTUSED,NOTUSED};
 
 int secureAnalogRead(int pin) {
-  delay(0.01);
-  analogRead(groundPin);
-  delay(0.01);
+  //delay(0.01);
+  //analogRead(groundPin);
+  //delay(0.01);
   return analogRead(pin);
   
 }

  char status;
  if(bmp180Temperature(T)) {
    Serial.println(T);
    delay(500);
    status = pressure.startPressure(3);
    if (status != 0) {
        delay(status);

  String c, v;
  switch (type) {
    case BMP180T:
      {
      double t;
      c = "BMP180T";
      if (bmp180Temperature(t)) v = String(t);
      else v = c + " Error";
      break;
      }

    case BMP180P:
      {
      double p;
      c = "BMP180P";
      if (bmp180Pressure(p)) v = String(p);
      else v = c + " Error";
      break;
      }

    case DHT22T:
      {
      float t = dht.readTemperature();    // Default temperature unit is ºC.
      c = "DHT22T";
      v = String(t);
      break;
      }

    case DHT22H:
      {
      float h = dht.readHumidity();
      c = "DHT22H";
      v = String(h);
      break;
      }
    case DHT22HI:
      {
      float h, t, hi;
      h = dht.readHumidity();
      t = dht.readTemperature(true);    // We need value in farenheit.
      hi = dht.computeHeatIndex(t,h);
      c = "DHT22HI";
      v = String(dht.convertFtoC(hi));
      break;
      }
  }
  sendCommand(c, v);
}
