60 lines
1.4 KiB
C
Raw Normal View History

2020-11-27 11:10:47 +01:00
#pragma once
//
// FILE: DHT12.h
// AUTHOR: Rob Tillaart
// PURPOSE: DHT_I2C library for Arduino .
2022-11-01 21:00:49 +01:00
// VERSION: 0.3.3
// HISTORY: See DHT12.cpp
2020-11-27 11:10:47 +01:00
// URL: https://github.com/RobTillaart/DHT12
//
2021-10-25 17:35:53 +02:00
2021-01-29 12:31:58 +01:00
#include "Arduino.h"
#include "Wire.h"
2022-11-01 21:00:49 +01:00
#define DHT12_LIB_VERSION (F("0.3.3"))
2021-12-16 15:58:14 +01:00
#define DHT12_OK 0
#define DHT12_ERROR_CHECKSUM -10
#define DHT12_ERROR_CONNECT -11
#define DHT12_MISSING_BYTES -12
2021-10-25 17:35:53 +02:00
class DHT12
{
public:
2022-11-01 21:00:49 +01:00
DHT12(TwoWire *wire); // to be tested explicitly
2020-11-27 11:10:47 +01:00
#if defined(ESP8266) || defined(ESP32)
2021-12-16 15:58:14 +01:00
bool begin(const uint8_t dataPin, const uint8_t clockPin);
2020-11-27 11:10:47 +01:00
#endif
2021-12-16 15:58:14 +01:00
bool begin();
bool isConnected();
2021-01-29 12:31:58 +01:00
int8_t read();
float getHumidity() { return _humidity + _humOffset; };
float getTemperature() { return _temperature + _tempOffset; };
2022-11-01 21:00:49 +01:00
// allows 1st order calibration
2021-01-29 12:31:58 +01:00
void setHumOffset(float offset) { _humOffset = offset; };
void setTempOffset(float offset) { _tempOffset = offset; };
float getHumOffset() { return _humOffset; };
float getTempOffset() { return _tempOffset; };
2021-10-25 17:35:53 +02:00
uint32_t lastRead() { return _lastRead; };
private:
2021-01-29 12:31:58 +01:00
float _humidity;
float _temperature;
float _humOffset;
float _tempOffset;
uint8_t _bits[5];
2021-10-25 17:35:53 +02:00
uint32_t _lastRead;
2021-01-29 12:31:58 +01:00
int _readSensor();
2020-11-27 11:10:47 +01:00
TwoWire* _wire;
};
2021-10-25 17:35:53 +02:00
2020-11-27 11:10:47 +01:00
// -- END OF FILE --