A minimal library for the DHT11.

Fork of DHT11 by Eric Fossum

Committer:
amithy
Date:
Thu Nov 09 22:14:56 2017 +0000
Revision:
2:983fdd709bf7
test export

Who changed what in which revision?

UserRevisionLine numberNew contents of line
amithy 2:983fdd709bf7 1 #ifndef DHT22_H
amithy 2:983fdd709bf7 2 #define DHT22_H
amithy 2:983fdd709bf7 3
amithy 2:983fdd709bf7 4 #include "mbed.h"
amithy 2:983fdd709bf7 5
amithy 2:983fdd709bf7 6 #define DHTLIB_OK 0
amithy 2:983fdd709bf7 7 #define DHTLIB_ERROR_CHECKSUM -1
amithy 2:983fdd709bf7 8 #define DHTLIB_ERROR_TIMEOUT -2
amithy 2:983fdd709bf7 9
amithy 2:983fdd709bf7 10 /** Class for the DHT22 sensor.
amithy 2:983fdd709bf7 11 *
amithy 2:983fdd709bf7 12 * Example:
amithy 2:983fdd709bf7 13 * @code
amithy 2:983fdd709bf7 14 * #include "mbed.h"
amithy 2:983fdd709bf7 15 * #include "Dht22.h"
amithy 2:983fdd709bf7 16 *
amithy 2:983fdd709bf7 17 * Serial pc(USBTX, USBRX);
amithy 2:983fdd709bf7 18 * Dht22 sensor(PTD7);
amithy 2:983fdd709bf7 19 *
amithy 2:983fdd709bf7 20 * int main() {
amithy 2:983fdd709bf7 21 * sensor.read()
amithy 2:983fdd709bf7 22 * pc.printf("T: %f, H: %d\r\n", sensor.getFahrenheit(), sensor.getHumidity());
amithy 2:983fdd709bf7 23 * }
amithy 2:983fdd709bf7 24 * @endcode
amithy 2:983fdd709bf7 25 */
amithy 2:983fdd709bf7 26 class Dht22
amithy 2:983fdd709bf7 27 {
amithy 2:983fdd709bf7 28 public:
amithy 2:983fdd709bf7 29 /** Construct the sensor object.
amithy 2:983fdd709bf7 30 *
amithy 2:983fdd709bf7 31 * @param pin PinName for the sensor pin.
amithy 2:983fdd709bf7 32 */
amithy 2:983fdd709bf7 33 Dht22(PinName const &p);
amithy 2:983fdd709bf7 34
amithy 2:983fdd709bf7 35 /** Update the humidity and temp from the sensor.
amithy 2:983fdd709bf7 36 *
amithy 2:983fdd709bf7 37 * @returns
amithy 2:983fdd709bf7 38 * 0 on success, otherwise error.
amithy 2:983fdd709bf7 39 */
amithy 2:983fdd709bf7 40 int read();
amithy 2:983fdd709bf7 41
amithy 2:983fdd709bf7 42 /** Get the temp(f) from the saved object.
amithy 2:983fdd709bf7 43 *
amithy 2:983fdd709bf7 44 * @returns
amithy 2:983fdd709bf7 45 * Fahrenheit float
amithy 2:983fdd709bf7 46 */
amithy 2:983fdd709bf7 47 float getFahrenheit();
amithy 2:983fdd709bf7 48
amithy 2:983fdd709bf7 49 /** Get the temp(c) from the saved object.
amithy 2:983fdd709bf7 50 *
amithy 2:983fdd709bf7 51 * @returns
amithy 2:983fdd709bf7 52 * Celsius int
amithy 2:983fdd709bf7 53 */
amithy 2:983fdd709bf7 54 int getCelsius();
amithy 2:983fdd709bf7 55
amithy 2:983fdd709bf7 56 /** Get the humidity from the saved object.
amithy 2:983fdd709bf7 57 *
amithy 2:983fdd709bf7 58 * @returns
amithy 2:983fdd709bf7 59 * Humidity percent int
amithy 2:983fdd709bf7 60 */
amithy 2:983fdd709bf7 61 int getHumidity();
amithy 2:983fdd709bf7 62
amithy 2:983fdd709bf7 63 private:
amithy 2:983fdd709bf7 64 /// percentage of humidity
amithy 2:983fdd709bf7 65 int _humidity;
amithy 2:983fdd709bf7 66 /// celsius
amithy 2:983fdd709bf7 67 int _temperature;
amithy 2:983fdd709bf7 68 /// pin to read the sensor info on
amithy 2:983fdd709bf7 69 DigitalInOut _pin;
amithy 2:983fdd709bf7 70 /// times startup (must settle for at least a second)
amithy 2:983fdd709bf7 71 Timer _timer;
amithy 2:983fdd709bf7 72 };
amithy 2:983fdd709bf7 73
amithy 2:983fdd709bf7 74 #endif