![](/media/cache/profiles/rect31045.png.50x50_q85.png)
Example of my library for the DHT11 temperature and humidity sendor
Dependencies: DHT11 TextLCD mbed
main.cpp@0:da7b1c04a659, 2014-09-11 (annotated)
- Committer:
- s_inoue_mbed
- Date:
- Thu Sep 11 13:50:10 2014 +0000
- Revision:
- 0:da7b1c04a659
Example of my library for the DHT11 temperature and humidity sendor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
s_inoue_mbed | 0:da7b1c04a659 | 1 | /* |
s_inoue_mbed | 0:da7b1c04a659 | 2 | * A program for the use of the DHT11, a temperature and humidity sensor |
s_inoue_mbed | 0:da7b1c04a659 | 3 | * Shigenori Inoue, September 10, 2014 |
s_inoue_mbed | 0:da7b1c04a659 | 4 | */ |
s_inoue_mbed | 0:da7b1c04a659 | 5 | |
s_inoue_mbed | 0:da7b1c04a659 | 6 | #include "mbed.h" |
s_inoue_mbed | 0:da7b1c04a659 | 7 | #include "TextLCD.h" |
s_inoue_mbed | 0:da7b1c04a659 | 8 | #include "DHT11.h" |
s_inoue_mbed | 0:da7b1c04a659 | 9 | |
s_inoue_mbed | 0:da7b1c04a659 | 10 | // LEDs for debugging |
s_inoue_mbed | 0:da7b1c04a659 | 11 | BusOut leds(LED4, LED3, LED2, LED1); |
s_inoue_mbed | 0:da7b1c04a659 | 12 | |
s_inoue_mbed | 0:da7b1c04a659 | 13 | // LCD module |
s_inoue_mbed | 0:da7b1c04a659 | 14 | TextLCD lcd(p25, p24, p12, p13, p14, p23); |
s_inoue_mbed | 0:da7b1c04a659 | 15 | |
s_inoue_mbed | 0:da7b1c04a659 | 16 | // Humidity sensor |
s_inoue_mbed | 0:da7b1c04a659 | 17 | DHT11 d(p18); |
s_inoue_mbed | 0:da7b1c04a659 | 18 | |
s_inoue_mbed | 0:da7b1c04a659 | 19 | // The main function |
s_inoue_mbed | 0:da7b1c04a659 | 20 | int main() |
s_inoue_mbed | 0:da7b1c04a659 | 21 | { |
s_inoue_mbed | 0:da7b1c04a659 | 22 | int state; |
s_inoue_mbed | 0:da7b1c04a659 | 23 | |
s_inoue_mbed | 0:da7b1c04a659 | 24 | lcd.cls(); |
s_inoue_mbed | 0:da7b1c04a659 | 25 | lcd.locate(0, 0); |
s_inoue_mbed | 0:da7b1c04a659 | 26 | lcd.printf("DHT11 Humidity"); |
s_inoue_mbed | 0:da7b1c04a659 | 27 | |
s_inoue_mbed | 0:da7b1c04a659 | 28 | while(true) { |
s_inoue_mbed | 0:da7b1c04a659 | 29 | state = d.readData(); |
s_inoue_mbed | 0:da7b1c04a659 | 30 | |
s_inoue_mbed | 0:da7b1c04a659 | 31 | if (state != DHT11::OK) { |
s_inoue_mbed | 0:da7b1c04a659 | 32 | lcd.locate(0, 1); |
s_inoue_mbed | 0:da7b1c04a659 | 33 | lcd.printf("Error: %d", state); |
s_inoue_mbed | 0:da7b1c04a659 | 34 | } else { |
s_inoue_mbed | 0:da7b1c04a659 | 35 | lcd.locate(0, 1); |
s_inoue_mbed | 0:da7b1c04a659 | 36 | lcd.printf("T: %dC, H: %d%%", d.readTemperature(), d.readHumidity()); |
s_inoue_mbed | 0:da7b1c04a659 | 37 | } |
s_inoue_mbed | 0:da7b1c04a659 | 38 | leds = leds + 1; |
s_inoue_mbed | 0:da7b1c04a659 | 39 | wait(2.0); |
s_inoue_mbed | 0:da7b1c04a659 | 40 | } |
s_inoue_mbed | 0:da7b1c04a659 | 41 | } |