GY-63_MS5611/libraries/DHT12/DHT12.h

60 lines
1.4 KiB
C
Raw Normal View History

2020-11-27 05:10:47 -05:00
#pragma once
//
// FILE: DHT12.h
// AUTHOR: Rob Tillaart
// PURPOSE: DHT_I2C library for Arduino .
2022-11-01 16:00:49 -04:00
// VERSION: 0.3.3
// HISTORY: See DHT12.cpp
2020-11-27 05:10:47 -05:00
// URL: https://github.com/RobTillaart/DHT12
//
2021-10-25 11:35:53 -04:00
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
#include "Wire.h"
2022-11-01 16:00:49 -04:00
#define DHT12_LIB_VERSION (F("0.3.3"))
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
2021-10-25 11:35:53 -04:00
class DHT12
{
public:
2022-11-01 16:00:49 -04:00
DHT12(TwoWire *wire); // to be tested explicitly
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();
2021-01-29 06:31:58 -05:00
int8_t read();
float getHumidity() { return _humidity + _humOffset; };
float getTemperature() { return _temperature + _tempOffset; };
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; };
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;
};
2021-10-25 11:35:53 -04:00
2020-11-27 05:10:47 -05:00
// -- END OF FILE --