Use INPUT_PULLUP

Previously, the mode was configured to INPUT and then written HIGH,
which works on AVR but isn't very portable. Instead, this uses the
INPUT_PULLUP pin mode (available since Arduino 1.0.1) which is portable.
This commit is contained in:
Matthijs Kooijman 2015-07-24 18:18:01 +02:00
parent 45a20da301
commit f9c3f323e3

View File

@ -21,8 +21,7 @@ DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
void DHT::begin(void) { void DHT::begin(void) {
// set up the pins! // set up the pins!
pinMode(_pin, INPUT); pinMode(_pin, INPUT_PULLUP);
digitalWrite(_pin, HIGH);
// Using this value makes sure that millis() - lastreadtime will be // Using this value makes sure that millis() - lastreadtime will be
// >= MIN_INTERVAL right away. Note that this assignment wraps around, // >= MIN_INTERVAL right away. Note that this assignment wraps around,
// but so will the subtraction. // but so will the subtraction.
@ -153,7 +152,7 @@ boolean DHT::read(bool force) {
delayMicroseconds(40); delayMicroseconds(40);
// Now start reading the data line to get the value from the DHT sensor. // Now start reading the data line to get the value from the DHT sensor.
pinMode(_pin, INPUT); pinMode(_pin, INPUT_PULLUP);
delayMicroseconds(10); // Delay a bit to let sensor pull data line low. delayMicroseconds(10); // Delay a bit to let sensor pull data line low.
// First expect a low signal for ~80 microseconds followed by a high signal // First expect a low signal for ~80 microseconds followed by a high signal