Lee Nam Cheol / Mbed OS lab02-temp-humi

Dependencies:   DHT

Files at this revision

API Documentation at this revision

Comitter:
namcheol
Date:
Wed Apr 15 07:32:46 2020 +0000
Parent:
0:f31836d48420
Commit message:
lab02-temp-humi

Changed in this revision

DHT.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f31836d48420 -r 5574e57d989b DHT.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DHT.lib	Wed Apr 15 07:32:46 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/Wimpie/code/DHT/#9b5b3200688f
diff -r f31836d48420 -r 5574e57d989b main.cpp
--- a/main.cpp	Sun Mar 29 19:41:28 2020 +0000
+++ b/main.cpp	Wed Apr 15 07:32:46 2020 +0000
@@ -1,18 +1,27 @@
 #include "mbed.h"
+#include "DHT.h"
 
-// https://os.mbed.com/docs/mbed-os/v5.15/tools/creating-a-new-program.html
-
-Serial pc(USBTX, USBRX, 115200);    // baud rate 115200
-DigitalOut led(LED1);               // led = LED1
+//https://os.mbed.com/users/Wimpie/code/DHT
+DHT sensor(A0, SEN11301P);  //sensor = SEM11301P
 
 int main()
 {
-    while (true) {
-        led = 0;
-        printf("LED1 is ON\r\n");
-        thread_sleep_for(500);
-        led = 1;
-        printf("LED1 is OFF\r\n");
-        thread_sleep_for(500);
+    int error;
+
+    printf("\r\n=============================================\r\n");
+    thread_sleep_for(1000);
+    while(true) {
+        error = sensor.readData();
+        if(error == 0) {
+            printf("Temperature:\t%4.2f C, %4.2f F, %4.2f K\r\n",
+                   sensor.ReadTemperature(CELCIUS),
+                   sensor.ReadTemperature(FARENHEIT),
+                   sensor.ReadTemperature(KELVIN));
+            printf("Humidity:\t%4.2f%%\r\n", sensor.ReadHumidity());
+            printf("=============================================\r\n");
+            thread_sleep_for(5000);
+        } else {
+            thread_sleep_for(1000);
+        }
     }
 }
\ No newline at end of file