This is an example program to fetch data of DHT11 Sensors

Dependencies:   mbed

Fork of DHT11_with_Nucleo by Adatgy2014

Revision:
9:a2918c6c37ee
Parent:
8:01e3281451e2
Child:
10:774c12ebf0f2
--- a/main.cpp	Tue Jan 06 11:33:45 2015 +0000
+++ b/main.cpp	Tue Jan 13 18:54:14 2015 +0000
@@ -6,7 +6,7 @@
 Serial pc(SERIAL_TX, SERIAL_RX); // Initialize UART connection
 // Use a terminal program (eg. TeraTerm).
 Timer tmr; //initialize timer
-char adat[40]; // Array for data
+uint64_t adat; // 64 bit variable for temporary data
 int i;
 
 // Function to initialize DHT11
@@ -24,6 +24,7 @@
     while(data_pin.read()) {}
     // 40 bit, 40 read out cycle
     for(i=0; i<40; i++) {
+        adat = adat << 1; // Shift for new number
         tmr.stop(); // Stop timer if runs
         tmr.reset();  // Reset timer
         // Wait until pin
@@ -33,7 +34,7 @@
         // If DHT11 HIGH longer than 40 micro seconds (hopefully 70 us)
         if(tmr.read_us() > 40) {
             // bit is 1
-            adat[i] = 1;
+            adat++;
         }
     }
 }
@@ -42,16 +43,12 @@
     pc.printf("Read the DHT11 temperature and humidity sensor!\n"); //Welcome message
     while(1) {
         if (mybutton == 0) { // Button is pressed
-            // Reset character array
-            for(i=0; i < 40; i++){
-                adat[i] = 0;
-            }
+            // Reset adat variable
+            adat = 0;
             myled = 1; // LED is ON
             dht_read(); // Call the function
             // Send result through UART result
-            for(i=0; i < 40; i++){
-                pc.printf("%d",adat[i]);
-            }
+            pc.printf("%X",adat);
             pc.printf("\n\r"); // Send a new line and carriage return.
             wait_ms(200); // Wait 0.2 sec till continue.
         } else {