mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
DHT22 with proteus.
I made this changes in the library to make it works with DHT22 sensor in proteus.
This commit is contained in:
parent
428e115b57
commit
e384d4aec6
15
DHT.cpp
15
DHT.cpp
@ -81,6 +81,7 @@ void DHT::begin(uint8_t usec) {
|
|||||||
*/
|
*/
|
||||||
float DHT::readTemperature(bool S, bool force) {
|
float DHT::readTemperature(bool S, bool force) {
|
||||||
float f = NAN;
|
float f = NAN;
|
||||||
|
float a,b;
|
||||||
|
|
||||||
if (read(force)) {
|
if (read(force)) {
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
@ -105,6 +106,13 @@ float DHT::readTemperature(bool S, bool force) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DHT22:
|
case DHT22:
|
||||||
|
a = data[2]<<8;
|
||||||
|
b = data[3];
|
||||||
|
f = (a + b)/10;
|
||||||
|
if (S) {
|
||||||
|
f = convertCtoF(f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case DHT21:
|
case DHT21:
|
||||||
f = ((word)(data[2] & 0x7F)) << 8 | data[3];
|
f = ((word)(data[2] & 0x7F)) << 8 | data[3];
|
||||||
f *= 0.1;
|
f *= 0.1;
|
||||||
@ -144,6 +152,7 @@ float DHT::convertFtoC(float f) { return (f - 32) * 0.55555; }
|
|||||||
*/
|
*/
|
||||||
float DHT::readHumidity(bool force) {
|
float DHT::readHumidity(bool force) {
|
||||||
float f = NAN;
|
float f = NAN;
|
||||||
|
float a,b;
|
||||||
if (read(force)) {
|
if (read(force)) {
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case DHT11:
|
case DHT11:
|
||||||
@ -151,6 +160,10 @@ float DHT::readHumidity(bool force) {
|
|||||||
f = data[0] + data[1] * 0.1;
|
f = data[0] + data[1] * 0.1;
|
||||||
break;
|
break;
|
||||||
case DHT22:
|
case DHT22:
|
||||||
|
a = data[0]<<8;
|
||||||
|
b = data[1];
|
||||||
|
f = (a + b)/10;
|
||||||
|
break;
|
||||||
case DHT21:
|
case DHT21:
|
||||||
f = ((word)data[0]) << 8 | data[1];
|
f = ((word)data[0]) << 8 | data[1];
|
||||||
f *= 0.1;
|
f *= 0.1;
|
||||||
@ -254,6 +267,8 @@ bool DHT::read(bool force) {
|
|||||||
digitalWrite(_pin, LOW);
|
digitalWrite(_pin, LOW);
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case DHT22:
|
case DHT22:
|
||||||
|
delay(20); // data sheet says at least 18ms, 20ms just to be safe
|
||||||
|
break;
|
||||||
case DHT21:
|
case DHT21:
|
||||||
delayMicroseconds(1100); // data sheet says "at least 1ms"
|
delayMicroseconds(1100); // data sheet says "at least 1ms"
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user