Tester for DHT22

Dependencies:   DHT mbed

Committer:
gert_lauritsen
Date:
Fri Feb 26 20:38:20 2016 +0000
Revision:
2:97f36e93b6e6
Parent:
1:781c47971406
Test til dht22

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gert_lauritsen 0:3d3909a13aff 1 #include "mbed.h"
gert_lauritsen 0:3d3909a13aff 2 #include "DHT.h"
gert_lauritsen 0:3d3909a13aff 3
gert_lauritsen 1:781c47971406 4
gert_lauritsen 0:3d3909a13aff 5 DigitalOut myled(LED1);
gert_lauritsen 2:97f36e93b6e6 6 DigitalOut Error(LED2);
gert_lauritsen 2:97f36e93b6e6 7 DHT dht22(p21,DHT22);
gert_lauritsen 0:3d3909a13aff 8
gert_lauritsen 0:3d3909a13aff 9 int main() {
gert_lauritsen 0:3d3909a13aff 10 printf("Starting!!!\r\n");
gert_lauritsen 0:3d3909a13aff 11 wait(1);
gert_lauritsen 0:3d3909a13aff 12 while(1) {
gert_lauritsen 0:3d3909a13aff 13 int err=dht22.readData();
gert_lauritsen 0:3d3909a13aff 14 if (err==0) {
gert_lauritsen 2:97f36e93b6e6 15 Error=0;
gert_lauritsen 0:3d3909a13aff 16 printf("T: %.1f C",dht22.ReadTemperature(CELCIUS));
gert_lauritsen 0:3d3909a13aff 17 printf(" H %.1f\% \n\r",dht22.ReadHumidity());
gert_lauritsen 0:3d3909a13aff 18 }
gert_lauritsen 2:97f36e93b6e6 19 else {
gert_lauritsen 2:97f36e93b6e6 20 Error=1;
gert_lauritsen 2:97f36e93b6e6 21 dht22.printErr(err);
gert_lauritsen 2:97f36e93b6e6 22 }
gert_lauritsen 1:781c47971406 23
gert_lauritsen 0:3d3909a13aff 24 myled = 1;
gert_lauritsen 2:97f36e93b6e6 25 wait(3);
gert_lauritsen 0:3d3909a13aff 26 myled = 0;
gert_lauritsen 2:97f36e93b6e6 27
gert_lauritsen 0:3d3909a13aff 28 }
gert_lauritsen 0:3d3909a13aff 29 }