Drivers and example program
Fork of Seeed_Grove_Temp_Humidity_Example by
main.cpp@2:5f336f6ec4d5, 2015-11-06 (annotated)
- Committer:
- alex0612
- Date:
- Fri Nov 06 16:38:49 2015 +0000
- Revision:
- 2:5f336f6ec4d5
- Parent:
- 0:c12c28a0f9e7
driver and example code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:c12c28a0f9e7 | 1 | |
sam_grove | 0:c12c28a0f9e7 | 2 | #include "mbed.h" |
sam_grove | 0:c12c28a0f9e7 | 3 | #include "DHT.h" |
sam_grove | 0:c12c28a0f9e7 | 4 | |
sam_grove | 0:c12c28a0f9e7 | 5 | DHT sensor(D4, DHT11); |
alex0612 | 2:5f336f6ec4d5 | 6 | DigitalOut myled(LED1); |
alex0612 | 2:5f336f6ec4d5 | 7 | Serial pc(USBTX, USBRX); // tx, rx |
sam_grove | 0:c12c28a0f9e7 | 8 | |
sam_grove | 0:c12c28a0f9e7 | 9 | int main() |
sam_grove | 0:c12c28a0f9e7 | 10 | { |
sam_grove | 0:c12c28a0f9e7 | 11 | int error = 0; |
sam_grove | 0:c12c28a0f9e7 | 12 | float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; |
sam_grove | 0:c12c28a0f9e7 | 13 | |
sam_grove | 0:c12c28a0f9e7 | 14 | while(1) { |
sam_grove | 0:c12c28a0f9e7 | 15 | wait(2.0f); |
sam_grove | 0:c12c28a0f9e7 | 16 | error = sensor.readData(); |
sam_grove | 0:c12c28a0f9e7 | 17 | if (0 == error) { |
sam_grove | 0:c12c28a0f9e7 | 18 | c = sensor.ReadTemperature(CELCIUS); |
sam_grove | 0:c12c28a0f9e7 | 19 | f = sensor.ReadTemperature(FARENHEIT); |
sam_grove | 0:c12c28a0f9e7 | 20 | k = sensor.ReadTemperature(KELVIN); |
sam_grove | 0:c12c28a0f9e7 | 21 | h = sensor.ReadHumidity(); |
sam_grove | 0:c12c28a0f9e7 | 22 | dp = sensor.CalcdewPoint(c, h); |
sam_grove | 0:c12c28a0f9e7 | 23 | dpf = sensor.CalcdewPointFast(c, h); |
alex0612 | 2:5f336f6ec4d5 | 24 | pc.printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f); |
alex0612 | 2:5f336f6ec4d5 | 25 | pc.printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf); |
sam_grove | 0:c12c28a0f9e7 | 26 | } else { |
alex0612 | 2:5f336f6ec4d5 | 27 | pc.printf("Error: %d\n", error); |
sam_grove | 0:c12c28a0f9e7 | 28 | } |
sam_grove | 0:c12c28a0f9e7 | 29 | } |
sam_grove | 0:c12c28a0f9e7 | 30 | } |