From 4980566e18797028590c6ae730d7fff9b565f164 Mon Sep 17 00:00:00 2001 From: niesteszeck Date: Fri, 22 Mar 2013 11:21:48 -0300 Subject: [PATCH] Added an example sketch --- .../idDHT11_Lib_example.ino | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 examples/idDHT11_Lib_example/idDHT11_Lib_example.ino diff --git a/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino b/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino new file mode 100644 index 0000000..8d7ceca --- /dev/null +++ b/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino @@ -0,0 +1,84 @@ +/* + Board int.0 int.1 int.2 int.3 int.4 int.5 + Uno, Ethernet 2 3 + Mega2560 2 3 21 20 19 18 + Leonardo 3 2 0 1 + Due (any pin, more info http://arduino.cc/en/Reference/AttachInterrupt) + */ + +#include + +int idDHT11pin = 2; //Digital pin for comunications +int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above) + +//declaration +void dht11_wrapper(); + +// Lib instantiate +idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper); + +void setup() +{ + Serial.begin(9600); + Serial.println("idDHT11 Example program"); + Serial.print("LIB version: "); + Serial.println(IDDHT11LIB_VERSION); + Serial.println("---------------"); +} +void dht11_wrapper() { + DHT11.isrCallback(); +} +void loop() +{ + Serial.print("\nRetrieving information from sensor: "); + Serial.print("Read sensor: "); + //delay(100); + DHT11.acquire(); + while (DHT11.acquiring()) + ; + int result = DHT11.getStatus(); + switch (result) + { + case IDDHTLIB_OK: + Serial.println("OK"); + break; + case IDDHTLIB_ERROR_CHECKSUM: + Serial.println("Error\n\r\tChecksum error"); + break; + case IDDHTLIB_ERROR_TIMEOUT: + Serial.println("Error\n\r\tTime out error"); + break; + case IDDHTLIB_ERROR_ACQUIRING: + Serial.println("Error\n\r\tAcquiring"); + break; + case IDDHTLIB_ERROR_DELTA: + Serial.println("Error\n\r\tDelta time to small"); + break; + case IDDHTLIB_ERROR_NOTSTARTED: + Serial.println("Error\n\r\tNot started"); + break; + default: + Serial.println("Unknown error"); + break; + } + Serial.print("Humidity (%): "); + Serial.println(DHT11.getHumidity(), 2); + + Serial.print("Temperature (oC): "); + Serial.println(DHT11.getCelsius(), 2); + + Serial.print("Temperature (oF): "); + Serial.println(DHT11.getFahrenheit(), 2); + + Serial.print("Temperature (K): "); + Serial.println(DHT11.getKelvin(), 2); + + Serial.print("Dew Point (oC): "); + Serial.println(DHT11.getDewPoint()); + + Serial.print("Dew Point Slow (oC): "); + Serial.println(DHT11.getDewPointSlow()); + + delay(2000); +} +