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

define an empty constructor and overload DHT::begin #196

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
40 changes: 40 additions & 0 deletions DHT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@
UINT32_MAX /**< Used programmatically for timeout. \
Not a timeout duration. Type: uint32_t. */

/**
* @brief Instantiates a default DHT class
*
*/
DHT::DHT() {
_pin = 2; // pin 2 set as the default data pin
_type = DHT11; // using the DHT11 sensor as the default sensor type.
// Note that pin 2 and DHT11 are just default values to initialize members
// _pin and _type in the class definition. They can be modified via
// DHT::begin(uint8_t pin, uint8_t type, uint8_t usec).
#ifdef __AVR
_bit = digitalPinToBitMask(_pin);
_port = digitalPinToPort(_pin);
#endif
_maxcycles =
microsecondsToClockCycles(1000); // 1 millisecond timeout for
// reading pulses from DHT sensor.
}

/*!
* @brief Instantiates a new DHT class
* @param pin
Expand Down Expand Up @@ -72,6 +91,27 @@ void DHT::begin(uint8_t usec) {
pullTime = usec;
}

/**
* @brief Setup sensor pins and set pull timings
*
* @param pin
* pin number that sensor is connected
* @param type
* type of sensor
* @param usec
* Optionally pass pull-up time (in microseconds) before DHT reading
* starts. Default is 55 (see function declaration in DHT.h).
*/
void DHT::begin(uint8_t pin, uint8_t type, uint8_t usec) {
_pin = pin;
_type = type;
#ifdef __AVR
_bit = digitalPinToBitMask(pin);
_port = digitalPinToPort(pin);
#endif
begin(usec);
}

/*!
* @brief Read temperature
* @param S
Expand Down
2 changes: 2 additions & 0 deletions DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ static const uint8_t AM2301{21}; /**< AM2301 */
*/
class DHT {
public:
DHT();
DHT(uint8_t pin, uint8_t type, uint8_t count = 6);
void begin(uint8_t usec = 55);
void begin(uint8_t pin, uint8_t type, uint8_t usec = 55);
float readTemperature(bool S = false, bool force = false);
float convertCtoF(float);
float convertFtoC(float);
Expand Down