Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DHT11_with_Nucleo by
Revision 9:a2918c6c37ee, committed 2015-01-13
- Comitter:
- kaliczp
- Date:
- Tue Jan 13 18:54:14 2015 +0000
- Parent:
- 8:01e3281451e2
- Child:
- 10:774c12ebf0f2
- Commit message:
- Let's use a binary number!
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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 {