checkpoint

Dependencies:   mbed Servo mbed-rtos 4DGL-uLCD-SE DHT PinDetect BME280

Revision:
13:6cb633e5010a
Parent:
12:c7c1603ec7fe
diff -r c7c1603ec7fe -r 6cb633e5010a main.cpp
--- a/main.cpp	Sat May 01 21:25:40 2021 +0000
+++ b/main.cpp	Sat May 01 23:21:58 2021 +0000
@@ -1,22 +1,25 @@
 #include "mbed.h"
-#include "DHT.h"
+//#include "DHT.h"
 #include "uLCD_4DGL.h"
 #include "rtos.h"
 #include "PinDetect.h"
 #include "Servo.h"
+#include "BME280.h"
 
 uLCD_4DGL lcd(p13,p14,p19); // serial tx, serial rx, reset pin;
-DHT dht(p18, DHT22);
-PinDetect bt1(p8);
+//DHT dht(p18, DHT22);
+PinDetect bt1(p5);
 PinDetect bt2(p7);
 PinDetect bt3(p6);
 Servo servo(p21);
 Mutex lcd_mutex;
-Serial blue(p28, p27);      //Bluetooth Module
+RawSerial blue(p28, p27);      //Bluetooth Module
+BME280 bme(p9, p10);
 
 
 float humidity;
-volatile float set_temp, curr_temp;
+volatile float set_temp;
+float curr_temp;
 volatile bool AC_on;
 
 // two interrupts for updating the set temperature
@@ -80,7 +83,7 @@
             if (blue.getc() == 's') {
                 if (blue.getc() == 'e') {
                     if (blue.getc() == 't') {
-//                        if (blue.getc() == ' ') {
+                        if (blue.getc() == ' ') {
                             printf("here!\n");
                             char msg[5];
                             msg[0] = blue.getc();
@@ -91,12 +94,13 @@
                             
                             sscanf(msg, "%f", &set_temp);
                             printf("%s", msg);
-//                        }
+
+                        }
                     }
                 }
             }
         }
-        Thread::yield();
+//        Thread::yield();
     }   
 }
 
@@ -142,17 +146,14 @@
     t2.start(&servo_control);
     t3.start(&bluetooth_control);
     
+    float temp_f;
     int code;
     
     // main thread, for updating temperature and humidity printouts on LCD
     while (1) {
-        code = dht.readData();  // error detection code for DHT22
-//        if (code != 0)
-//            continue;
-            
-//        printf("code=%d\n", code);
-        curr_temp = dht.ReadTemperature(CELCIUS);
-        humidity = dht.ReadHumidity();
+        curr_temp = bme.getTemperature();
+//        curr_temp = (temp_f - 32.0) * 5.0 / 9.0;
+        humidity = bme.getHumidity();
         
         lcd_mutex.lock();
             lcd.locate(5, 2);
@@ -161,7 +162,7 @@
             
             lcd.locate(0, 6);
             lcd.color(BLUE);
-            lcd.printf(" %.0f%%", humidity);
+            lcd.printf(" %.0f%% ", humidity);
         lcd_mutex.unlock();
         
         Thread::wait(2000);