DHT

Dependencies:   SDFileSystem

Committer:
david8251
Date:
Thu Jul 20 09:05:08 2017 +0000
Revision:
0:97c2d4128ff3
DHT

Who changed what in which revision?

UserRevisionLine numberNew contents of line
david8251 0:97c2d4128ff3 1 #include "mbed.h"
david8251 0:97c2d4128ff3 2 #include "DHT.h"
david8251 0:97c2d4128ff3 3
david8251 0:97c2d4128ff3 4 DHT sensor(D7,DHT22);
david8251 0:97c2d4128ff3 5
david8251 0:97c2d4128ff3 6 void task_DHT();
david8251 0:97c2d4128ff3 7
david8251 0:97c2d4128ff3 8 int main()
david8251 0:97c2d4128ff3 9 {
david8251 0:97c2d4128ff3 10
david8251 0:97c2d4128ff3 11 while(1) {
david8251 0:97c2d4128ff3 12 task_DHT();
david8251 0:97c2d4128ff3 13 }
david8251 0:97c2d4128ff3 14 }
david8251 0:97c2d4128ff3 15 void task_DHT(){
david8251 0:97c2d4128ff3 16 int error = 0;
david8251 0:97c2d4128ff3 17 int h, c,f;
david8251 0:97c2d4128ff3 18 float dp = 0.0f;
david8251 0:97c2d4128ff3 19
david8251 0:97c2d4128ff3 20 wait(2.0f);
david8251 0:97c2d4128ff3 21 error = sensor.readData();
david8251 0:97c2d4128ff3 22 if (0 == error) {
david8251 0:97c2d4128ff3 23 c = sensor.ReadTemperature(CELCIUS);
david8251 0:97c2d4128ff3 24 f = sensor.ReadTemperature(FARENHEIT);
david8251 0:97c2d4128ff3 25 h = sensor.ReadHumidity();
david8251 0:97c2d4128ff3 26 dp = sensor.CalcdewPoint(c, h);
david8251 0:97c2d4128ff3 27
david8251 0:97c2d4128ff3 28 printf("Temperature in Celcius: %d, Farenheit %d\r\n", c, f);
david8251 0:97c2d4128ff3 29 printf("Humidity is %d, Dewpoint: %4.2f\r\n\n", h, dp);
david8251 0:97c2d4128ff3 30 } else {
david8251 0:97c2d4128ff3 31 printf("Error: %d\r\n", error);
david8251 0:97c2d4128ff3 32 }
david8251 0:97c2d4128ff3 33 }