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.
Revision 0:97e328a3466a, committed 2020-06-04
- Comitter:
- xuuuu
- Date:
- Thu Jun 04 10:14:54 2020 +0000
- Commit message:
- A mbed code to control a multifunctional automatic fan.
Changed in this revision
diff -r 000000000000 -r 97e328a3466a TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Thu Jun 04 10:14:54 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
diff -r 000000000000 -r 97e328a3466a main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Jun 04 10:14:54 2020 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+#include "TextLCD.h"
+DigitalInOut data_pin(p6); // Activate digital in as dht11 Pin
+DigitalOut pin5(p5); // Switch the fan on and off
+TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7
+Timer tmr; //initialize timer
+uint64_t adat; // 64 bit variable for temporary data
+int i;
+void dht_read(void) {
+ data_pin.output(); // Set p6 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();
+ // Wait until the end of 80 us low
+ while(!data_pin.read()) {}
+ // Wait until end of 80 us high
+ 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
+ while(!data_pin.read()) {}
+ tmr.start();
+ while(data_pin.read()) {}
+ // If DHT11 HIGH longer than 40 micro seconds (hopefully 70 us)
+ if(tmr.read_us() > 40) {
+ // bit is 1
+ adat++;
+ }
+ }
+}
+int main() {
+ while(1) {
+ adat = 0;
+ dht_read(); // Call the function
+ int abc = (adat & 0x0000000000ff0000) >> 16;
+ lcd.printf("Temperature:\n");
+ lcd.printf("%d",abc); // Temperature
+ if(abc > 20) pin5 = 1; // Fan is ON
+ else pin5 = 0; //Fan is OFF
+ wait(2); // Wait 2 sec till continue.
+ lcd.cls(); // Clear the screen
+ }
+}
\ No newline at end of file
diff -r 000000000000 -r 97e328a3466a mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jun 04 10:14:54 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file