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.
Dependencies: mbed MbedJSONValue HTTPClient TFT_fonts SPI_TFT_ILI9341 mbed-rtos picojsontest NTPClient SDFileSystem EthernetInterface DHT Stepper_Motor_X27168
Dht11.h@4:1eea5edaffc4, 2019-05-01 (annotated)
- Committer:
- aalbul3
- Date:
- Wed May 01 04:11:18 2019 +0000
- Revision:
- 4:1eea5edaffc4
This is a test
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| aalbul3 | 4:1eea5edaffc4 | 1 | #ifndef DHT11_H |
| aalbul3 | 4:1eea5edaffc4 | 2 | #define DHT11_H |
| aalbul3 | 4:1eea5edaffc4 | 3 | |
| aalbul3 | 4:1eea5edaffc4 | 4 | #include "mbed.h" |
| aalbul3 | 4:1eea5edaffc4 | 5 | |
| aalbul3 | 4:1eea5edaffc4 | 6 | #define DHTLIB_OK 0 |
| aalbul3 | 4:1eea5edaffc4 | 7 | #define DHTLIB_ERROR_CHECKSUM -1 |
| aalbul3 | 4:1eea5edaffc4 | 8 | #define DHTLIB_ERROR_TIMEOUT -2 |
| aalbul3 | 4:1eea5edaffc4 | 9 | |
| aalbul3 | 4:1eea5edaffc4 | 10 | /** Class for the DHT11 sensor. |
| aalbul3 | 4:1eea5edaffc4 | 11 | * |
| aalbul3 | 4:1eea5edaffc4 | 12 | * Example: |
| aalbul3 | 4:1eea5edaffc4 | 13 | * @code |
| aalbul3 | 4:1eea5edaffc4 | 14 | * #include "mbed.h" |
| aalbul3 | 4:1eea5edaffc4 | 15 | * #include "Dht11.h" |
| aalbul3 | 4:1eea5edaffc4 | 16 | * |
| aalbul3 | 4:1eea5edaffc4 | 17 | * Serial pc(USBTX, USBRX); |
| aalbul3 | 4:1eea5edaffc4 | 18 | * Dht11 sensor(PTD7); |
| aalbul3 | 4:1eea5edaffc4 | 19 | * |
| aalbul3 | 4:1eea5edaffc4 | 20 | * int main() { |
| aalbul3 | 4:1eea5edaffc4 | 21 | * sensor.read() |
| aalbul3 | 4:1eea5edaffc4 | 22 | * pc.printf("T: %f, H: %d\r\n", sensor.getFahrenheit(), sensor.getHumidity()); |
| aalbul3 | 4:1eea5edaffc4 | 23 | * } |
| aalbul3 | 4:1eea5edaffc4 | 24 | * @endcode |
| aalbul3 | 4:1eea5edaffc4 | 25 | */ |
| aalbul3 | 4:1eea5edaffc4 | 26 | class Dht11 |
| aalbul3 | 4:1eea5edaffc4 | 27 | { |
| aalbul3 | 4:1eea5edaffc4 | 28 | public: |
| aalbul3 | 4:1eea5edaffc4 | 29 | /** Construct the sensor object. |
| aalbul3 | 4:1eea5edaffc4 | 30 | * |
| aalbul3 | 4:1eea5edaffc4 | 31 | * @param pin PinName for the sensor pin. |
| aalbul3 | 4:1eea5edaffc4 | 32 | */ |
| aalbul3 | 4:1eea5edaffc4 | 33 | Dht11(PinName const &p); |
| aalbul3 | 4:1eea5edaffc4 | 34 | |
| aalbul3 | 4:1eea5edaffc4 | 35 | /** Update the humidity and temp from the sensor. |
| aalbul3 | 4:1eea5edaffc4 | 36 | * |
| aalbul3 | 4:1eea5edaffc4 | 37 | * @returns |
| aalbul3 | 4:1eea5edaffc4 | 38 | * 0 on success, otherwise error. |
| aalbul3 | 4:1eea5edaffc4 | 39 | */ |
| aalbul3 | 4:1eea5edaffc4 | 40 | int read(); |
| aalbul3 | 4:1eea5edaffc4 | 41 | |
| aalbul3 | 4:1eea5edaffc4 | 42 | /** Get the temp(f) from the saved object. |
| aalbul3 | 4:1eea5edaffc4 | 43 | * |
| aalbul3 | 4:1eea5edaffc4 | 44 | * @returns |
| aalbul3 | 4:1eea5edaffc4 | 45 | * Fahrenheit float |
| aalbul3 | 4:1eea5edaffc4 | 46 | */ |
| aalbul3 | 4:1eea5edaffc4 | 47 | float getFahrenheit(); |
| aalbul3 | 4:1eea5edaffc4 | 48 | |
| aalbul3 | 4:1eea5edaffc4 | 49 | /** Get the temp(c) from the saved object. |
| aalbul3 | 4:1eea5edaffc4 | 50 | * |
| aalbul3 | 4:1eea5edaffc4 | 51 | * @returns |
| aalbul3 | 4:1eea5edaffc4 | 52 | * Celsius int |
| aalbul3 | 4:1eea5edaffc4 | 53 | */ |
| aalbul3 | 4:1eea5edaffc4 | 54 | int getCelsius(); |
| aalbul3 | 4:1eea5edaffc4 | 55 | |
| aalbul3 | 4:1eea5edaffc4 | 56 | /** Get the humidity from the saved object. |
| aalbul3 | 4:1eea5edaffc4 | 57 | * |
| aalbul3 | 4:1eea5edaffc4 | 58 | * @returns |
| aalbul3 | 4:1eea5edaffc4 | 59 | * Humidity percent int |
| aalbul3 | 4:1eea5edaffc4 | 60 | */ |
| aalbul3 | 4:1eea5edaffc4 | 61 | int getHumidity(); |
| aalbul3 | 4:1eea5edaffc4 | 62 | |
| aalbul3 | 4:1eea5edaffc4 | 63 | private: |
| aalbul3 | 4:1eea5edaffc4 | 64 | /// percentage of humidity |
| aalbul3 | 4:1eea5edaffc4 | 65 | int _humidity; |
| aalbul3 | 4:1eea5edaffc4 | 66 | /// celsius |
| aalbul3 | 4:1eea5edaffc4 | 67 | int _temperature; |
| aalbul3 | 4:1eea5edaffc4 | 68 | /// pin to read the sensor info on |
| aalbul3 | 4:1eea5edaffc4 | 69 | DigitalInOut _pin; |
| aalbul3 | 4:1eea5edaffc4 | 70 | /// times startup (must settle for at least a second) |
| aalbul3 | 4:1eea5edaffc4 | 71 | Timer _timer; |
| aalbul3 | 4:1eea5edaffc4 | 72 | }; |
| aalbul3 | 4:1eea5edaffc4 | 73 | |
| aalbul3 | 4:1eea5edaffc4 | 74 | #endif |