Program očitava temperaturu i vlažnost zraka u prostoriji pomoću senzora DHT11. Očitane vrijednosti ispisuje na računalu u programu Tera Term. Za vlažnost zraka manju od 60% svijetli zelena LED, a za vlažnost zraka veću od 60% pali se crvena LED. Pritiskom na tipkalo prekida se rad programa na 5sekundi. Odbrojavanje se prikazuje na 7-segmentnom displey-u. Za to vrijeme ugašene su sve LED. Nakon isteka 5 sekundi program nastavlja sa radom tamo di je prethodno stao. Žuta LED predstavlja ticker i blinka svake 0,2 sekunde i time pokazuje da se program izvršava.
Diff: dht11.h
- Revision:
- 0:d2e26e6fa11b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dht11.h Tue Apr 06 12:12:07 2021 +0000 @@ -0,0 +1,74 @@ +#ifndef DHT11_H +#define DHT11_H + +#include "mbed.h" + +#define DHTLIB_OK 0 +#define DHTLIB_ERROR_CHECKSUM -1 +#define DHTLIB_ERROR_TIMEOUT -2 + +/** Class for the DHT11 sensor. + * + * Example: + * @code + * #include "mbed.h" + * #include "Dht11.h" + * + * Serial pc(USBTX, USBRX); + * Dht11 sensor(PTD7); + * + * int main() { + * sensor.read(); + * pc.printf("T: %f, H: %d\r\n", sensor.getFahrenheit(), sensor.getHumidity()); + * } + * @endcode + */ +class Dht11 +{ +public: + /** Construct the sensor object. + * + * @param pin PinName for the sensor pin. + */ + Dht11(PinName const &p); + + /** Update the humidity and temp from the sensor. + * + * @returns + * 0 on success, otherwise error. + */ + int read(); + + /** Get the temp(f) from the saved object. + * + * @returns + * Fahrenheit float + */ + float getFahrenheit(); + + /** Get the temp(c) from the saved object. + * + * @returns + * Celsius int + */ + int getCelsius(); + + /** Get the humidity from the saved object. + * + * @returns + * Humidity percent int + */ + int getHumidity(); + +private: + /// percentage of humidity + int _humidity; + /// celsius + int _temperature; + /// pin to read the sensor info on + DigitalInOut _pin; + /// times startup (must settle for at least a second) + Timer _timer; +}; + +#endif