2020-11-27 05:10:47 -05:00
|
|
|
#pragma once
|
2017-12-12 16:04:06 -05:00
|
|
|
//
|
|
|
|
// FILE: DHT12.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// PURPOSE: DHT_I2C library for Arduino .
|
2020-11-27 05:10:47 -05:00
|
|
|
// VERSION: 0.2.1
|
2017-12-12 16:04:06 -05:00
|
|
|
// HISTORY: See DHT12.cpp
|
2020-11-27 05:10:47 -05:00
|
|
|
// URL: https://github.com/RobTillaart/DHT12
|
2017-12-12 16:04:06 -05:00
|
|
|
//
|
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
#include <Wire.h>
|
2017-12-12 16:04:06 -05:00
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
#define DHT12_LIB_VERSION "0.2.1"
|
2017-12-12 16:04:06 -05:00
|
|
|
|
2017-12-21 07:05:45 -05:00
|
|
|
#define DHT12_OK 0
|
|
|
|
#define DHT12_ERROR_CHECKSUM -10
|
|
|
|
#define DHT12_ERROR_CONNECT -11
|
|
|
|
#define DHT12_MISSING_BYTES -12
|
2017-12-12 16:04:06 -05:00
|
|
|
|
|
|
|
class DHT12
|
|
|
|
{
|
|
|
|
public:
|
2020-11-27 05:10:47 -05:00
|
|
|
explicit DHT12();
|
|
|
|
explicit DHT12(TwoWire *wire); // to be tested explicitly
|
2017-12-21 07:05:45 -05:00
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
#if defined(ESP8266) || defined(ESP32)
|
|
|
|
void begin(const uint8_t dataPin, const uint8_t clockPin);
|
|
|
|
#endif
|
2017-12-21 07:05:45 -05:00
|
|
|
void begin();
|
2017-12-12 16:04:06 -05:00
|
|
|
|
|
|
|
int8_t read();
|
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
// preferred interface
|
|
|
|
float getHumidity() { return humidity; };
|
|
|
|
float getTemperature() { return temperature; };
|
|
|
|
|
|
|
|
// members will become private in the future.
|
2017-12-12 16:04:06 -05:00
|
|
|
float humidity;
|
|
|
|
float temperature;
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint8_t bits[5];
|
|
|
|
int _readSensor();
|
2020-11-27 05:10:47 -05:00
|
|
|
TwoWire* _wire;
|
2017-12-12 16:04:06 -05:00
|
|
|
};
|
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
// -- END OF FILE --
|