ajeet prajapati
/
DHT11-HelloWorld1
DHT11 example for WIZwiki-W7500
Fork of DHT11-HelloWorld by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "DHT.h" 00003 00004 #define DHT_DATA_PIN D4 00005 Serial out(USBTX,USBRX); 00006 DHT sensor(DHT_DATA_PIN, DHT11); //DHT(PinName pin, eType DHTtype) 00007 00008 int main() 00009 { 00010 int error = 0; 00011 float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; 00012 00013 while(1) 00014 { 00015 wait(2.0f); //wait 2 second 00016 error = sensor.readData(); 00017 // c = sensor.ReadTemperature(CELCIUS); //read error value 00018 // out.printf(" Celcius: %4.2f",c); 00019 if (error == 0) //case: no error 00020 { 00021 c = sensor.ReadTemperature(CELCIUS); 00022 f = sensor.ReadTemperature(FARENHEIT); 00023 k = sensor.ReadTemperature(KELVIN); 00024 h = sensor.ReadHumidity(); 00025 dp = sensor.CalcdewPoint(c, h); 00026 dpf = sensor.CalcdewPointFast(c, h); 00027 printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f); 00028 printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf); 00029 } 00030 else //case: error 00031 { 00032 printf("Error: %d\n", error); 00033 } 00034 } 00035 }
Generated on Fri Jul 22 2022 07:45:28 by 1.7.2