DHT11+AQM0802

Dependencies:   mbed DHT AQM0802A

Committer:
takusei25
Date:
Fri Jun 11 00:48:54 2021 +0000
Revision:
2:a17a95217222
Parent:
0:c12c28a0f9e7
mbed+DHT11+AQM0802

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:c12c28a0f9e7 1
sam_grove 0:c12c28a0f9e7 2 #include "mbed.h"
sam_grove 0:c12c28a0f9e7 3 #include "DHT.h"
takusei25 2:a17a95217222 4 #include "AQM0802A.h"
takusei25 2:a17a95217222 5 //#include "TextLCD.h"
sam_grove 0:c12c28a0f9e7 6
takusei25 2:a17a95217222 7 //I2C i2c_lcd(p28,p27);
takusei25 2:a17a95217222 8 AQM0802A lcd(p28, p27);
takusei25 2:a17a95217222 9 Serial pc(USBTX, USBRX);
takusei25 2:a17a95217222 10 //AQM0802 lcd(p28, p27);
takusei25 2:a17a95217222 11 //TextLCD_I2C lcd(&i2c_lcd, 0x7C, TextLCD::LCD8x2, TextLCD::ST7032_3V3);
takusei25 2:a17a95217222 12
takusei25 2:a17a95217222 13 DHT sensor(p23, DHT11);
sam_grove 0:c12c28a0f9e7 14
sam_grove 0:c12c28a0f9e7 15 int main()
sam_grove 0:c12c28a0f9e7 16 {
sam_grove 0:c12c28a0f9e7 17 int error = 0;
takusei25 2:a17a95217222 18 float h = 0.0f, c = 0.0f;
sam_grove 0:c12c28a0f9e7 19 while(1) {
sam_grove 0:c12c28a0f9e7 20 wait(2.0f);
sam_grove 0:c12c28a0f9e7 21 error = sensor.readData();
sam_grove 0:c12c28a0f9e7 22 if (0 == error) {
sam_grove 0:c12c28a0f9e7 23 c = sensor.ReadTemperature(CELCIUS);
takusei25 2:a17a95217222 24 //f = sensor.ReadTemperature(FARENHEIT);
takusei25 2:a17a95217222 25 //k = sensor.ReadTemperature(KELVIN);
sam_grove 0:c12c28a0f9e7 26 h = sensor.ReadHumidity();
takusei25 2:a17a95217222 27 //dp = sensor.CalcdewPoint(c, h);
takusei25 2:a17a95217222 28 //dpf = sensor.CalcdewPointFast(c, h);
takusei25 2:a17a95217222 29 pc.printf("Celcius: %4.2f\n",c);
takusei25 2:a17a95217222 30 pc.printf("Humidity is %4.2f\n", h);
takusei25 2:a17a95217222 31 lcd.cls();
takusei25 2:a17a95217222 32 lcd.setCursor(0,0);
takusei25 2:a17a95217222 33 lcd.printf("%.1f oC",c);
takusei25 2:a17a95217222 34 lcd.setCursor(0,1);
takusei25 2:a17a95217222 35 lcd.printf("%.1f %%",h);
takusei25 2:a17a95217222 36 //lcd.lcd_setCursor(0,0);
takusei25 2:a17a95217222 37 //lcd.print("%2.2f",c);
takusei25 2:a17a95217222 38 //lcd.printf("hello");
takusei25 2:a17a95217222 39 //lcd.lcd_setCursor(0,1);
takusei25 2:a17a95217222 40 //lcd.print("%2.2f",h);
takusei25 2:a17a95217222 41 //lcd.lcd_printStr("1E");
sam_grove 0:c12c28a0f9e7 42 } else {
sam_grove 0:c12c28a0f9e7 43 printf("Error: %d\n", error);
sam_grove 0:c12c28a0f9e7 44 }
sam_grove 0:c12c28a0f9e7 45 }
sam_grove 0:c12c28a0f9e7 46 }
takusei25 2:a17a95217222 47 /*
takusei25 2:a17a95217222 48 #include <mbed.h>
takusei25 2:a17a95217222 49 #include <AQM0802A.h>
takusei25 2:a17a95217222 50
takusei25 2:a17a95217222 51 AQM0802A lcd(p28, p27); // <-- this !
takusei25 2:a17a95217222 52 Ticker ticker;
takusei25 2:a17a95217222 53
takusei25 2:a17a95217222 54 void tick() {
takusei25 2:a17a95217222 55 static int count = 0;
takusei25 2:a17a95217222 56 lcd.cls();
takusei25 2:a17a95217222 57 lcd.printf("Hello\n %d", count++);
takusei25 2:a17a95217222 58 }
takusei25 2:a17a95217222 59
takusei25 2:a17a95217222 60 int main() {
takusei25 2:a17a95217222 61 ticker.attach(&tick, 0.1);
takusei25 2:a17a95217222 62 while(1) {
takusei25 2:a17a95217222 63 }
takusei25 2:a17a95217222 64 }
takusei25 2:a17a95217222 65 */