2021-12-16 16:44:08 +01:00
|
|
|
#pragma once
|
2020-11-27 11:10:47 +01:00
|
|
|
//
|
2013-08-28 13:57:45 +02:00
|
|
|
// FILE: dht.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2021-12-16 16:44:08 +01:00
|
|
|
// VERSION: 0.1.35
|
2020-11-27 11:10:47 +01:00
|
|
|
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino. AVR optimized
|
|
|
|
// URL: https://github.com/RobTillaart/DHTlib
|
|
|
|
// http://arduino.cc/playground/Main/DHTLib
|
2013-08-28 13:57:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
#if ARDUINO < 100
|
|
|
|
#include <WProgram.h>
|
2014-10-15 08:00:59 +02:00
|
|
|
#include <pins_arduino.h> // fix for broken pre 1.0 version - TODO TEST
|
2013-08-28 13:57:45 +02:00
|
|
|
#else
|
|
|
|
#include <Arduino.h>
|
|
|
|
#endif
|
|
|
|
|
2014-06-01 09:48:06 +02:00
|
|
|
|
2021-12-16 16:44:08 +01:00
|
|
|
#define DHT_LIB_VERSION (F("0.1.35"))
|
2014-06-01 09:48:06 +02:00
|
|
|
|
2021-02-03 17:20:20 +01:00
|
|
|
#define DHTLIB_OK 0
|
|
|
|
#define DHTLIB_ERROR_CHECKSUM -1
|
|
|
|
#define DHTLIB_ERROR_TIMEOUT -2
|
|
|
|
#define DHTLIB_ERROR_CONNECT -3
|
|
|
|
#define DHTLIB_ERROR_ACK_L -4
|
|
|
|
#define DHTLIB_ERROR_ACK_H -5
|
|
|
|
|
|
|
|
|
2013-08-28 13:57:45 +02:00
|
|
|
class dht
|
|
|
|
{
|
|
|
|
public:
|
2018-03-26 22:30:03 +02:00
|
|
|
dht() { _disableIRQ = false; };
|
2014-06-26 20:48:20 +02:00
|
|
|
// return values:
|
|
|
|
// DHTLIB_OK
|
|
|
|
// DHTLIB_ERROR_CHECKSUM
|
|
|
|
// DHTLIB_ERROR_TIMEOUT
|
2014-10-15 08:00:59 +02:00
|
|
|
// DHTLIB_ERROR_CONNECT
|
|
|
|
// DHTLIB_ERROR_ACK_L
|
|
|
|
// DHTLIB_ERROR_ACK_H
|
2015-03-01 11:53:47 +01:00
|
|
|
int8_t read11(uint8_t pin);
|
|
|
|
int8_t read(uint8_t pin);
|
2017-12-12 20:58:58 +01:00
|
|
|
int8_t read12(uint8_t pin);
|
2014-06-26 20:48:20 +02:00
|
|
|
|
2018-04-03 19:08:27 +02:00
|
|
|
inline int8_t read21(uint8_t pin) { return read(pin); };
|
|
|
|
inline int8_t read22(uint8_t pin) { return read(pin); };
|
|
|
|
inline int8_t read33(uint8_t pin) { return read(pin); };
|
|
|
|
inline int8_t read44(uint8_t pin) { return read(pin); };
|
2017-12-12 20:58:58 +01:00
|
|
|
inline int8_t read2301(uint8_t pin) { return read(pin); };
|
|
|
|
inline int8_t read2302(uint8_t pin) { return read(pin); };
|
|
|
|
inline int8_t read2303(uint8_t pin) { return read(pin); };
|
|
|
|
inline int8_t read2320(uint8_t pin) { return read(pin); };
|
|
|
|
inline int8_t read2322(uint8_t pin) { return read(pin); };
|
2018-04-03 19:08:27 +02:00
|
|
|
|
|
|
|
bool getDisableIRQ() { return _disableIRQ; };
|
|
|
|
void setDisableIRQ(bool b ) { _disableIRQ = b; };
|
2018-03-26 22:30:03 +02:00
|
|
|
|
2017-07-27 01:18:02 +02:00
|
|
|
float humidity;
|
|
|
|
float temperature;
|
2013-08-28 13:57:45 +02:00
|
|
|
|
|
|
|
private:
|
2014-02-08 13:53:52 +01:00
|
|
|
uint8_t bits[5]; // buffer to receive data
|
2015-03-01 11:53:47 +01:00
|
|
|
int8_t _readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBits);
|
2018-03-26 22:30:03 +02:00
|
|
|
bool _disableIRQ;
|
2013-08-28 13:57:45 +02:00
|
|
|
};
|
2021-12-16 16:44:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|