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 3:6228ab73d420, committed 2015-01-06
- Comitter:
- kaliczp
- Date:
- Tue Jan 06 00:10:33 2015 +0000
- Parent:
- 2:4469aa7f4995
- Child:
- 4:62b680fac6ed
- Commit message:
- Make a function to initialize DHT11
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Jan 06 00:01:51 2015 +0000 +++ b/main.cpp Tue Jan 06 00:10:33 2015 +0000 @@ -4,17 +4,22 @@ DigitalIn mybutton(USER_BUTTON); // Activate button DigitalInOut data_pin(A0); // Activate digital in +// Function to initialize DHT11 +void dht_read(void) { + data_pin.output(); // Set A0 as output + // Initialize measurement > 18 ms low + data_pin = 0; + wait_ms(20); + // After high and release the pin switch input mode + data_pin = 1; + data_pin.input(); +} + int main() { while(1) { if (mybutton == 0) { // Button is pressed myled = 1; // LED is ON - data_pin.output(); // Set A0 as output - // Initialize measurement > 18 ms low - data_pin = 0; - wait_ms(20); - // After high and release the pin switch input mode - data_pin = 1; - data_pin.input(); + dht_read(); // Call the function wait_ms(200); // Wait 0.2 sec till continue. } else { myled = 0; // LED is OFF