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 .
|
2022-11-01 16:00:49 -04:00
|
|
|
// VERSION: 0.3.3
|
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
|
|
|
//
|
|
|
|
|
2021-10-25 11:35:53 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
#include "Arduino.h"
|
|
|
|
#include "Wire.h"
|
2017-12-12 16:04:06 -05:00
|
|
|
|
2022-11-01 16:00:49 -04:00
|
|
|
#define DHT12_LIB_VERSION (F("0.3.3"))
|
2017-12-12 16:04:06 -05:00
|
|
|
|
2021-12-16 09:58:14 -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
|
|
|
|
2021-10-25 11:35:53 -04:00
|
|
|
|
2017-12-12 16:04:06 -05:00
|
|
|
class DHT12
|
|
|
|
{
|
|
|
|
public:
|
2022-11-01 16:00:49 -04:00
|
|
|
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)
|
2021-12-16 09:58:14 -05:00
|
|
|
bool begin(const uint8_t dataPin, const uint8_t clockPin);
|
2020-11-27 05:10:47 -05:00
|
|
|
#endif
|
2021-12-16 09:58:14 -05:00
|
|
|
bool begin();
|
|
|
|
|
|
|
|
bool isConnected();
|
2017-12-12 16:04:06 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
int8_t read();
|
|
|
|
float getHumidity() { return _humidity + _humOffset; };
|
|
|
|
float getTemperature() { return _temperature + _tempOffset; };
|
2017-12-12 16:04:06 -05:00
|
|
|
|
2022-11-01 16:00:49 -04:00
|
|
|
// allows 1st order calibration
|
2021-01-29 06:31:58 -05:00
|
|
|
void setHumOffset(float offset) { _humOffset = offset; };
|
|
|
|
void setTempOffset(float offset) { _tempOffset = offset; };
|
|
|
|
float getHumOffset() { return _humOffset; };
|
|
|
|
float getTempOffset() { return _tempOffset; };
|
2021-10-25 11:35:53 -04:00
|
|
|
uint32_t lastRead() { return _lastRead; };
|
2017-12-12 16:04:06 -05:00
|
|
|
|
|
|
|
private:
|
2021-01-29 06:31:58 -05:00
|
|
|
float _humidity;
|
|
|
|
float _temperature;
|
|
|
|
float _humOffset;
|
|
|
|
float _tempOffset;
|
|
|
|
uint8_t _bits[5];
|
2021-10-25 11:35:53 -04:00
|
|
|
uint32_t _lastRead;
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
int _readSensor();
|
2020-11-27 05:10:47 -05:00
|
|
|
TwoWire* _wire;
|
2017-12-12 16:04:06 -05:00
|
|
|
};
|
|
|
|
|
2021-10-25 11:35:53 -04:00
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
// -- END OF FILE --
|