lamyae zerrouki / Mbed 2 deprecated DISCO-L053C8_ePD_demo

Dependencies:   EPD_GDE021A1 lib_dht22 mbed

Fork of DISCO-L053C8_ePD_demo by ST

Files at this revision

API Documentation at this revision

Comitter:
lamyaezerrouki
Date:
Tue Oct 04 12:05:18 2016 +0000
Parent:
1:5c48647597ad
Commit message:
Debut

Changed in this revision

lib_dht22.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 5c48647597ad -r a78e4e7d9be2 lib_dht22.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib_dht22.lib	Tue Oct 04 12:05:18 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/co657_sjc80/code/lib_dht22/#257ba13e416e
diff -r 5c48647597ad -r a78e4e7d9be2 main.cpp
--- a/main.cpp	Tue Jun 02 15:23:27 2015 +0000
+++ b/main.cpp	Tue Oct 04 12:05:18 2016 +0000
@@ -1,5 +1,6 @@
 #include "mbed.h"
 #include "EPD_GDE021A1.h"
+#include "dht22.h"
 
 #define EPD_CS       PA_15
 #define EPD_DC       PB_11
@@ -9,10 +10,15 @@
 #define EPD_SPI_MOSI PB_5
 #define EPD_SPI_MISO PB_4
 #define EPD_SPI_SCK  PB_3
+#define PTB18        PC_15
 
 EPD_GDE021A1 epd(EPD_CS, EPD_DC, EPD_RESET, EPD_BUSY, EPD_POWER, EPD_SPI_MOSI, EPD_SPI_MISO, EPD_SPI_SCK);
 
 DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+
+Serial host(USBTX, USBRX);
+DHT22 dht22(PTB18);
 
 //width 48
 //height 26
@@ -48,6 +54,7 @@
 int main()
 {
     led1 = 1;
+    DHT22_data_t dht22_data;
     
     epd.Clear(EPD_COLOR_WHITE);  
     epd.DisplayStringAtLine(5, (uint8_t*)"MBED", CENTER_MODE);
@@ -56,10 +63,36 @@
     epd.DrawImage(130, 0, 48, 26, Battery_img);
     epd.DrawRect(50, 4, 60, 4);
     epd.RefreshDisplay();
-    wait(2);
+    wait(1);
   
     while(1) {
-        led1 = !led1;
-        wait(1);
+        led1 = 1;
+        wait_ms(500);
+        
+        dht22.read(&dht22_data);
+        
+        float temperature = dht22_data.temp / 10.0f;
+        float humidity = dht22_data.humidity / 10.0f;
+        
+        host.printf("Temperature: %2.2f    Humidity: %2.2f%%\r\n", temperature, humidity);
+        wait_ms(500);
+        
+        char str1[5], str2[5];
+        sprintf(str1, "%.1f", temperature);
+        sprintf(str2, "%.1f", humidity);
+        
+        led1 = 0;
+        led2 = 1;
+        
+        epd.Clear(EPD_COLOR_WHITE);  
+        epd.DisplayStringAtLine(5, (uint8_t*)"Adrien", CENTER_MODE);
+        epd.DisplayStringAtLine(3, (uint8_t*)"Temperature: ", LEFT_MODE);
+        epd.DisplayStringAtLine(3, (uint8_t*)str1, RIGHT_MODE);
+        epd.DisplayStringAtLine(2, (uint8_t*)"Humidity: ", LEFT_MODE);
+        epd.DisplayStringAtLine(2, (uint8_t*)str2, RIGHT_MODE);
+        epd.RefreshDisplay();
+        
+        led2 = 0;
+        wait_ms(500);
     }
 }