mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
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:
parent
45a20da301
commit
f9c3f323e3
5
DHT.cpp
5
DHT.cpp
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user