diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b92380a --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# Vi files +*~ + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/DHT.cpp b/DHT.cpp index 86ad91c..2093cb6 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -8,7 +8,16 @@ written by Adafruit Industries #define MIN_INTERVAL 2000 -DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) { +// Old constructor. +//DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) { + +/* + * New constructor. + * + * Note that count is now ignored as the DHT reading algorithm adjusts itself + * based on the speed of the processor. + */ +DHT::DHT(uint8_t pin, uint8_t type) { _pin = pin; _type = type; #ifdef __AVR @@ -17,10 +26,9 @@ DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) { #endif _maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for // reading pulses from DHT sensor. - // Note that count is now ignored as the DHT reading algorithm adjusts itself - // basd on the speed of the processor. } + void DHT::begin(void) { // set up the pins! pinMode(_pin, INPUT_PULLUP); @@ -152,8 +160,12 @@ boolean DHT::read(bool force) { InterruptLock lock; // End the start signal by setting data line high for 40 microseconds. - digitalWrite(_pin, HIGH); - delayMicroseconds(40); + //digitalWrite(_pin, HIGH); + //delayMicroseconds(40); + // WEB: This is an error. DHT tries to pull the line low as soon as it came back to high. + // therefore the low-high transition after the start signal "low" needs to be realised by + // the pullup resistor only, uC pin must already be in INPUT mode. + // ref: https://github.com/adafruit/DHT-sensor-library/issues/48 // Now start reading the data line to get the value from the DHT sensor. pinMode(_pin, INPUT_PULLUP); diff --git a/DHT.h b/DHT.h index d81f6db..bb2ae10 100644 --- a/DHT.h +++ b/DHT.h @@ -37,11 +37,28 @@ written by Adafruit Industries class DHT { public: - DHT(uint8_t pin, uint8_t type, uint8_t count=6); + // Note that count is now ignored as the DHT reading algorithm adjusts itself + // based on the speed of the processor. + DHT(uint8_t pin, uint8_t type, uint8_t count) { + DHT(pin, type); + }; + DHT(uint8_t pin, uint8_t type); void begin(void); + float readFahrenheit(bool force=false) { + return readTemperature(true, force); + }; + float readCelcius(bool force=false) { + return readTemperature(false, force); + }; float readTemperature(bool S=false, bool force=false); float convertCtoF(float); float convertFtoC(float); + float computeHeatIndexFahrenheit(float temperature, float percentHumidity) { + return computeHeatIndex(temperature, percentHumidity, true); + }; + float computeHeatIndexCelcius(float temperature, float percentHumidity) { + return computeHeatIndex(temperature, percentHumidity, false); + }; float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true); float readHumidity(bool force=false); boolean read(bool force=false); @@ -59,6 +76,7 @@ class DHT { uint32_t expectPulse(bool level); + void _init(uint8_t pin, uint8_t type); }; class InterruptLock {