Program za ispit

Dependencies:   mbed

Committer:
Filip10
Date:
Fri Mar 29 18:02:34 2019 +0000
Revision:
0:ff77d67fd52a
.

Who changed what in which revision?

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