Skip to content

Commit 14d8168

Browse files
Merge pull request adafruit#3 from leprasmurf/master
Convert Celcius to Fahrenheit.
2 parents cffd745 + a3d1dc7 commit 14d8168

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

DHT.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ void DHT::begin(void) {
1919
_lastreadtime = 0;
2020
}
2121

22-
float DHT::readTemperature(void) {
22+
//boolean S == Scale. True == Farenheit; False == Celcius
23+
float DHT::readTemperature(bool S) {
2324
float f;
2425

2526
if (read()) {
2627
switch (_type) {
2728
case DHT11:
2829
f = data[2];
30+
if(S)
31+
f = convertCtoF(f);
32+
2933
return f;
3034
case DHT22:
3135
case DHT21:
@@ -35,6 +39,8 @@ float DHT::readTemperature(void) {
3539
f /= 10;
3640
if (data[2] & 0x80)
3741
f *= -1;
42+
if(S)
43+
f = convertCtoF(f);
3844

3945
return f;
4046
}
@@ -43,6 +49,10 @@ float DHT::readTemperature(void) {
4349
return NAN;
4450
}
4551

52+
float DHT::convertCtoF(float c) {
53+
return c * 9 / 5 + 32;
54+
}
55+
4656
float DHT::readHumidity(void) {
4757
float f;
4858
if (read()) {

DHT.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class DHT {
2929
public:
3030
DHT(uint8_t pin, uint8_t type);
3131
void begin(void);
32-
float readTemperature(void);
32+
float readTemperature(bool);
33+
float convertCtoF(float);
3334
float readHumidity(void);
3435

3536
};

0 commit comments

Comments
 (0)