mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
Merge pull request #3 from leprasmurf/master
Convert Celcius to Fahrenheit.
This commit is contained in:
commit
14d816819c
12
DHT.cpp
12
DHT.cpp
@ -19,13 +19,17 @@ void DHT::begin(void) {
|
|||||||
_lastreadtime = 0;
|
_lastreadtime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DHT::readTemperature(void) {
|
//boolean S == Scale. True == Farenheit; False == Celcius
|
||||||
|
float DHT::readTemperature(bool S) {
|
||||||
float f;
|
float f;
|
||||||
|
|
||||||
if (read()) {
|
if (read()) {
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case DHT11:
|
case DHT11:
|
||||||
f = data[2];
|
f = data[2];
|
||||||
|
if(S)
|
||||||
|
f = convertCtoF(f);
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
case DHT22:
|
case DHT22:
|
||||||
case DHT21:
|
case DHT21:
|
||||||
@ -35,6 +39,8 @@ float DHT::readTemperature(void) {
|
|||||||
f /= 10;
|
f /= 10;
|
||||||
if (data[2] & 0x80)
|
if (data[2] & 0x80)
|
||||||
f *= -1;
|
f *= -1;
|
||||||
|
if(S)
|
||||||
|
f = convertCtoF(f);
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
@ -43,6 +49,10 @@ float DHT::readTemperature(void) {
|
|||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float DHT::convertCtoF(float c) {
|
||||||
|
return c * 9 / 5 + 32;
|
||||||
|
}
|
||||||
|
|
||||||
float DHT::readHumidity(void) {
|
float DHT::readHumidity(void) {
|
||||||
float f;
|
float f;
|
||||||
if (read()) {
|
if (read()) {
|
||||||
|
3
DHT.h
3
DHT.h
@ -29,7 +29,8 @@ class DHT {
|
|||||||
public:
|
public:
|
||||||
DHT(uint8_t pin, uint8_t type);
|
DHT(uint8_t pin, uint8_t type);
|
||||||
void begin(void);
|
void begin(void);
|
||||||
float readTemperature(void);
|
float readTemperature(bool);
|
||||||
|
float convertCtoF(float);
|
||||||
float readHumidity(void);
|
float readHumidity(void);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user