DHT11 sensor test for Stage 1 Engineering at the University of York

Dependencies:   DHT11 UoY-serial

Files at this revision

API Documentation at this revision

Comitter:
ajp109
Date:
Thu Sep 16 15:37:20 2021 +0000
Parent:
1:acb591685a28
Commit message:
Initial commit of DHT11-test

Changed in this revision

DHT11.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DHT11.lib	Thu Sep 16 15:37:20 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/ajp109/code/DHT11/#11d0770eb603
--- a/main.cpp	Thu Feb 04 17:12:01 2021 +0000
+++ b/main.cpp	Thu Sep 16 15:37:20 2021 +0000
@@ -1,14 +1,19 @@
 #include "mbed.h"
+#include "UoY-serial.h"
+#include "DHT11.h"
 
-DigitalOut green(D2);
-DigitalOut red(D3);
+// D2 is the data pin name on the Nucleo board
+DHT11 sensor(D2);
 
 int main()
 {
-    while (true) {
-        green = true;
-        thread_sleep_for(500);
-        green = false;
-        thread_sleep_for(2500);
+    while(true) {
+        // Print temperature and humidity
+        printf("Temp: %d\n", sensor.readTemperature());
+        printf("  RH: %d%%\n", sensor.readHumidity());
+        
+        // Wait 2 seconds before doing it again
+        thread_sleep_for(2000);
     }
 }
+