DHT11 and LCD, humidity, temperature, dew point

Dependencies:   Freetronics_16x2_LCD mbed

Committer:
fblanc
Date:
Tue Feb 24 12:41:17 2015 +0000
Revision:
0:5e787e0e8ab6
test ST nucleo L152RE OK

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fblanc 0:5e787e0e8ab6 1 #include "mbed.h"
fblanc 0:5e787e0e8ab6 2 #include "freetronicsLCDShield.h"
fblanc 0:5e787e0e8ab6 3 #include "DHT.h"
fblanc 0:5e787e0e8ab6 4
fblanc 0:5e787e0e8ab6 5 freetronicsLCDShield lcd(D8, D9, D4, D5, D6, D7, D3, A0);
fblanc 0:5e787e0e8ab6 6 DHT sensor(A5, DHT11);
fblanc 0:5e787e0e8ab6 7 DigitalOut myled(LED1);
fblanc 0:5e787e0e8ab6 8 Ticker flipper;
fblanc 0:5e787e0e8ab6 9 bool up=true;
fblanc 0:5e787e0e8ab6 10 void readBP()
fblanc 0:5e787e0e8ab6 11 {
fblanc 0:5e787e0e8ab6 12 float bp=lcd.readButton();
fblanc 0:5e787e0e8ab6 13 if (bp<0.25)
fblanc 0:5e787e0e8ab6 14 up=true;
fblanc 0:5e787e0e8ab6 15 else if (bp<0.5)
fblanc 0:5e787e0e8ab6 16 up=false;
fblanc 0:5e787e0e8ab6 17 }
fblanc 0:5e787e0e8ab6 18 int main()
fblanc 0:5e787e0e8ab6 19 {
fblanc 0:5e787e0e8ab6 20 flipper.attach(&readBP, 0.1);
fblanc 0:5e787e0e8ab6 21 int error = 0;
fblanc 0:5e787e0e8ab6 22 float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f;
fblanc 0:5e787e0e8ab6 23 // turn on the back light (it's off by default)
fblanc 0:5e787e0e8ab6 24 lcd.setBackLight(true);
fblanc 0:5e787e0e8ab6 25 lcd.cls();
fblanc 0:5e787e0e8ab6 26 // print the first line and wait 3 sec
fblanc 0:5e787e0e8ab6 27 lcd.printf("mbed DHT11");
fblanc 0:5e787e0e8ab6 28 wait(3);
fblanc 0:5e787e0e8ab6 29
fblanc 0:5e787e0e8ab6 30 // print the counter prefix; the number will be printed in the while loop
fblanc 0:5e787e0e8ab6 31
fblanc 0:5e787e0e8ab6 32
fblanc 0:5e787e0e8ab6 33
fblanc 0:5e787e0e8ab6 34
fblanc 0:5e787e0e8ab6 35 while (1) {
fblanc 0:5e787e0e8ab6 36
fblanc 0:5e787e0e8ab6 37 error = sensor.readData();
fblanc 0:5e787e0e8ab6 38 if (0 == error) {
fblanc 0:5e787e0e8ab6 39 c = sensor.ReadTemperature(CELCIUS);
fblanc 0:5e787e0e8ab6 40 f = sensor.ReadTemperature(FARENHEIT);
fblanc 0:5e787e0e8ab6 41 k = sensor.ReadTemperature(KELVIN);
fblanc 0:5e787e0e8ab6 42 h = sensor.ReadHumidity();
fblanc 0:5e787e0e8ab6 43 dp = sensor.CalcdewPoint(c, h);
fblanc 0:5e787e0e8ab6 44 dpf = sensor.CalcdewPointFast(c, h);
fblanc 0:5e787e0e8ab6 45 if(up==true) {
fblanc 0:5e787e0e8ab6 46 lcd.setCursorPosition(0, 0);
fblanc 0:5e787e0e8ab6 47 lcd.printf("Temperature %4.2f ",c);
fblanc 0:5e787e0e8ab6 48 lcd.setCursorPosition(1, 0);
fblanc 0:5e787e0e8ab6 49 lcd.printf("Humidity %4.2f ", h);
fblanc 0:5e787e0e8ab6 50 }
fblanc 0:5e787e0e8ab6 51 if(up==false) {
fblanc 0:5e787e0e8ab6 52
fblanc 0:5e787e0e8ab6 53 lcd.setCursorPosition(0, 0);
fblanc 0:5e787e0e8ab6 54 lcd.printf("Humidity %4.2f ", h);
fblanc 0:5e787e0e8ab6 55 lcd.setCursorPosition(1, 0);
fblanc 0:5e787e0e8ab6 56 lcd.printf("Dew point %4.2f ",dp);
fblanc 0:5e787e0e8ab6 57 }
fblanc 0:5e787e0e8ab6 58 } else {
fblanc 0:5e787e0e8ab6 59
fblanc 0:5e787e0e8ab6 60 lcd.setCursorPosition(0, 0);
fblanc 0:5e787e0e8ab6 61 lcd.printf("mbed DHT11 ");
fblanc 0:5e787e0e8ab6 62 lcd.setCursorPosition(1, 0);
fblanc 0:5e787e0e8ab6 63 lcd.printf("Error: %d ", error);
fblanc 0:5e787e0e8ab6 64 }
fblanc 0:5e787e0e8ab6 65
fblanc 0:5e787e0e8ab6 66
fblanc 0:5e787e0e8ab6 67 wait(0.5f);
fblanc 0:5e787e0e8ab6 68 }
fblanc 0:5e787e0e8ab6 69 }