Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DHT11 by
Dht22.h
00001 #ifndef DHT22_H 00002 #define DHT22_H 00003 00004 #include "mbed.h" 00005 00006 #define DHTLIB_OK 0 00007 #define DHTLIB_ERROR_CHECKSUM -1 00008 #define DHTLIB_ERROR_TIMEOUT -2 00009 00010 /** Class for the DHT22 sensor. 00011 * 00012 * Example: 00013 * @code 00014 * #include "mbed.h" 00015 * #include "Dht22.h" 00016 * 00017 * Serial pc(USBTX, USBRX); 00018 * Dht22 sensor(PTD7); 00019 * 00020 * int main() { 00021 * sensor.read() 00022 * pc.printf("T: %f, H: %d\r\n", sensor.getFahrenheit(), sensor.getHumidity()); 00023 * } 00024 * @endcode 00025 */ 00026 class Dht22 00027 { 00028 public: 00029 /** Construct the sensor object. 00030 * 00031 * @param pin PinName for the sensor pin. 00032 */ 00033 Dht22(PinName const &p); 00034 00035 /** Update the humidity and temp from the sensor. 00036 * 00037 * @returns 00038 * 0 on success, otherwise error. 00039 */ 00040 int read(); 00041 00042 /** Get the temp(f) from the saved object. 00043 * 00044 * @returns 00045 * Fahrenheit float 00046 */ 00047 float getFahrenheit(); 00048 00049 /** Get the temp(c) from the saved object. 00050 * 00051 * @returns 00052 * Celsius int 00053 */ 00054 int getCelsius(); 00055 00056 /** Get the humidity from the saved object. 00057 * 00058 * @returns 00059 * Humidity percent int 00060 */ 00061 int getHumidity(); 00062 00063 private: 00064 /// percentage of humidity 00065 int _humidity; 00066 /// celsius 00067 int _temperature; 00068 /// pin to read the sensor info on 00069 DigitalInOut _pin; 00070 /// times startup (must settle for at least a second) 00071 Timer _timer; 00072 }; 00073 00074 #endif
Generated on Thu Jul 14 2022 22:40:00 by
1.7.2
