![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Temp and Humidity sensor example. DHT11
Fork of Seeed_Grove_Temp_Humidity_Example by
main.cpp@2:2a62f7420371, 2017-11-20 (annotated)
- Committer:
- anywill
- Date:
- Mon Nov 20 03:38:28 2017 +0000
- Revision:
- 2:2a62f7420371
- Parent:
- 0:c12c28a0f9e7
STM32 Nucleo F103RB+ DHT11;
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" |
anywill | 2:2a62f7420371 | 4 | //串口助手不支持中文输出 |
sam_grove | 0:c12c28a0f9e7 | 5 | DHT sensor(D4, DHT11); |
anywill | 2:2a62f7420371 | 6 | Serial pc(SERIAL_TX, SERIAL_RX); |
sam_grove | 0:c12c28a0f9e7 | 7 | int main() |
sam_grove | 0:c12c28a0f9e7 | 8 | { |
sam_grove | 0:c12c28a0f9e7 | 9 | int error = 0; |
sam_grove | 0:c12c28a0f9e7 | 10 | float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; |
sam_grove | 0:c12c28a0f9e7 | 11 | |
sam_grove | 0:c12c28a0f9e7 | 12 | while(1) { |
sam_grove | 0:c12c28a0f9e7 | 13 | wait(2.0f); |
sam_grove | 0:c12c28a0f9e7 | 14 | error = sensor.readData(); |
sam_grove | 0:c12c28a0f9e7 | 15 | if (0 == error) { |
sam_grove | 0:c12c28a0f9e7 | 16 | c = sensor.ReadTemperature(CELCIUS); |
sam_grove | 0:c12c28a0f9e7 | 17 | f = sensor.ReadTemperature(FARENHEIT); |
sam_grove | 0:c12c28a0f9e7 | 18 | k = sensor.ReadTemperature(KELVIN); |
sam_grove | 0:c12c28a0f9e7 | 19 | h = sensor.ReadHumidity(); |
sam_grove | 0:c12c28a0f9e7 | 20 | dp = sensor.CalcdewPoint(c, h); |
sam_grove | 0:c12c28a0f9e7 | 21 | dpf = sensor.CalcdewPointFast(c, h); |
anywill | 2:2a62f7420371 | 22 | pc.printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f); |
anywill | 2:2a62f7420371 | 23 | pc.printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf); |
sam_grove | 0:c12c28a0f9e7 | 24 | } else { |
anywill | 2:2a62f7420371 | 25 | pc.printf("Error: %d\n", error); |
sam_grove | 0:c12c28a0f9e7 | 26 | } |
sam_grove | 0:c12c28a0f9e7 | 27 | } |
sam_grove | 0:c12c28a0f9e7 | 28 | } |