From 8f46f27b660e6ed94323abbfc65e4b99d64e85c6 Mon Sep 17 00:00:00 2001 From: leprasmurf Date: Wed, 22 Feb 2012 22:20:19 -0500 Subject: [PATCH 1/2] Modified readTemperature() prototype. Added prototype for new function. --- DHT.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DHT.h b/DHT.h index 553329e..11e9101 100644 --- a/DHT.h +++ b/DHT.h @@ -29,7 +29,8 @@ class DHT { public: DHT(uint8_t pin, uint8_t type); void begin(void); - float readTemperature(void); + float readTemperature(bool); + float convertCtoF(float); float readHumidity(void); }; From a3d1dc78bf789ac859069e12931f880d3f55ca06 Mon Sep 17 00:00:00 2001 From: leprasmurf Date: Wed, 22 Feb 2012 22:26:16 -0500 Subject: [PATCH 2/2] Added option for converting to Fahrenheit --- DHT.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/DHT.cpp b/DHT.cpp index 79e9027..8bba81b 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -19,13 +19,17 @@ void DHT::begin(void) { _lastreadtime = 0; } -float DHT::readTemperature(void) { +//boolean S == Scale. True == Farenheit; False == Celcius +float DHT::readTemperature(bool S) { float f; if (read()) { switch (_type) { case DHT11: f = data[2]; + if(S) + f = convertCtoF(f); + return f; case DHT22: case DHT21: @@ -35,6 +39,8 @@ float DHT::readTemperature(void) { f /= 10; if (data[2] & 0x80) f *= -1; + if(S) + f = convertCtoF(f); return f; } @@ -43,6 +49,10 @@ float DHT::readTemperature(void) { return NAN; } +float DHT::convertCtoF(float c) { + return c * 9 / 5 + 32; +} + float DHT::readHumidity(void) { float f; if (read()) {