ITI "DallaChiesa" 2019 / Mbed 2 deprecated STMNucleoF401RE_ExampleCode_08_DHT11

Dependencies:   mbed DHT TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "DHT.h"
00003 #include "TextLCD.h"
00004 #define   DHT_DATA_PIN  D7
00005 
00006 TextLCD lcd(D10,D11,D5,D4,D3,D2); // rs, e, d4-d7
00007 Serial out(USBTX,USBRX);
00008 DHT sensor(DHT_DATA_PIN, DHT11);                    //DHT(PinName pin, eType DHTtype)
00009  
00010 int main()
00011 {
00012     int error = 0;
00013     float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f;
00014  
00015   //  while(1) 
00016     {
00017         wait(2.0f);                                 //wait 2 second
00018         error = sensor.readData(); 
00019        // c   = sensor.ReadTemperature(CELCIUS);                 //read error value
00020       //   out.printf(" Celcius: %4.2f",c);
00021         if (error == 0)                             //case: no error 
00022         {
00023             c   = sensor.ReadTemperature(CELCIUS);
00024             f   = sensor.ReadTemperature(FARENHEIT);
00025             k   = sensor.ReadTemperature(KELVIN);
00026             h   = sensor.ReadHumidity();
00027             //dp  = sensor.CalcdewPoint(c, h);
00028             //dpf = sensor.CalcdewPointFast(c, h);
00029             lcd.printf("Temp: %4.1f C \n", c);
00030             lcd.printf("Umid: %4.1f \n", h);
00031             
00032             printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f);
00033             printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf);
00034         } 
00035         else                                        //case: error
00036         {
00037             printf("Error: %d\n", error);
00038         }
00039     }
00040 }