Skip to content

Commit

Permalink
Added option for converting to Fahrenheit
Browse files Browse the repository at this point in the history
  • Loading branch information
leprasmurf committed Feb 23, 2012
1 parent 8f46f27 commit a3d1dc7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion DHT.cpp
Expand Up @@ -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:
Expand All @@ -35,6 +39,8 @@ float DHT::readTemperature(void) {
f /= 10;
if (data[2] & 0x80)
f *= -1;
if(S)
f = convertCtoF(f);

return f;
}
Expand All @@ -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()) {
Expand Down

0 comments on commit a3d1dc7

Please sign in to comment.