61 lines
1.2 KiB
C
Raw Normal View History

2020-11-27 11:10:47 +01:00
#pragma once
//
// FILE: DHT12.h
// AUTHOR: Rob Tillaart
2023-02-09 18:45:30 +01:00
// VERSION: 0.4.0
// PURPOSE: Arduino library for I2C DHT12 temperature and humidity sensor.
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"
2023-02-09 18:45:30 +01:00
#define DHT12_LIB_VERSION (F("0.4.0"))
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:
2023-02-09 18:45:30 +01:00
DHT12(TwoWire *wire = &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();
2023-02-09 18:45:30 +01:00
float getHumidity();
float getTemperature();
2022-11-01 21:00:49 +01:00
// allows 1st order calibration
2023-02-09 18:45:30 +01:00
void setHumOffset(float offset = 0);
void setTempOffset(float offset = 0);
float getHumOffset();
float getTempOffset();
uint32_t 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;
2023-02-09 18:45:30 +01:00
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
2023-02-09 18:45:30 +01:00
// -- END OF FILE --