Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DHT22 with proteus. #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions DHT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void DHT::begin(uint8_t usec) {
*/
float DHT::readTemperature(bool S, bool force) {
float f = NAN;
float a,b;

if (read(force)) {
switch (_type) {
Expand All @@ -105,6 +106,13 @@ float DHT::readTemperature(bool S, bool force) {
}
break;
case DHT22:
a = data[2]<<8;
b = data[3];
f = (a + b)/10;
if (S) {
f = convertCtoF(f);
}
break;
case DHT21:
f = ((word)(data[2] & 0x7F)) << 8 | data[3];
f *= 0.1;
Expand Down Expand Up @@ -144,13 +152,18 @@ float DHT::convertFtoC(float f) { return (f - 32) * 0.55555; }
*/
float DHT::readHumidity(bool force) {
float f = NAN;
float a,b;
if (read(force)) {
switch (_type) {
case DHT11:
case DHT12:
f = data[0] + data[1] * 0.1;
break;
case DHT22:
a = data[0]<<8;
b = data[1];
f = (a + b)/10;
break;
case DHT21:
f = ((word)data[0]) << 8 | data[1];
f *= 0.1;
Expand Down Expand Up @@ -254,6 +267,8 @@ bool DHT::read(bool force) {
digitalWrite(_pin, LOW);
switch (_type) {
case DHT22:
delay(20); // data sheet says at least 18ms, 20ms just to be safe
break;
case DHT21:
delayMicroseconds(1100); // data sheet says "at least 1ms"
break;
Expand Down