AC with Bluetooth Control

Dependencies:   4DGL-uLCD-SE mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
fmaxwell6
Date:
Tue Mar 14 19:26:45 2017 +0000
Commit message:
AC controlled with bluetooth

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
TMP36.h 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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Tue Mar 14 19:26:45 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TMP36.h	Tue Mar 14 19:26:45 2017 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+
+//Setup a new class for TMP36 sensor
+class TMP36
+{
+public:
+    TMP36(PinName pin);
+    TMP36();
+    operator float ();
+    float read();
+private:
+//class sets up the AnalogIn pin
+    AnalogIn _pin;
+};
+
+TMP36::TMP36(PinName pin) : _pin(pin)
+{
+// _pin(pin) means pass pin to the AnalogIn constructor
+}
+
+float TMP36::read()
+{
+//convert sensor reading to temperature in degrees C
+    return ((_pin.read()*3.3)-0.500)*100.0;
+}
+//overload of float conversion (avoids needing to type .read() in equations)
+TMP36::operator float ()
+{
+//convert sensor reading to temperature in degrees C
+    return ((_pin.read()*3.3)-0.500)*100.0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Mar 14 19:26:45 2017 +0000
@@ -0,0 +1,93 @@
+#include "mbed.h"
+#include "uLCD_4DGL.h"
+#include "TMP36.h"
+#include "rtos.h"
+uLCD_4DGL uLCD(p28, p27, p30); // serial tx, serial rx, reset pin;
+TMP36 myTMP36(p15);
+DigitalOut Ctrl(p21);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+PwmOut mymotor(p22);
+RawSerial blue(p9,p10);
+Mutex uLCD_mutex; 
+
+double speed = 0.0;
+float tempC, tempF;
+
+void Tempature_thread(){
+    while(1){
+         tempC = myTMP36.read();
+         //convert to degrees F
+         tempF = (9.0*tempC)/5.0 + 32.0;
+         uLCD_mutex.lock();
+         uLCD.locate(0,0);
+         uLCD.printf("The Temperature is: %3.1f F \n", tempF);
+         uLCD_mutex.unlock();
+         wait(1);
+    }
+}
+int main()
+{
+     blue.baud(9600);
+     char bnum='1';
+     Ctrl = 1;
+     uLCD.reset();
+     Thread t0;
+     t0.start(Tempature_thread);
+     while(1) 
+     {
+         if(bnum == '1'){
+             led1 = 1;
+             led2 = 0;
+             led3 = 0;
+             uLCD_mutex.lock();
+             uLCD.locate(0,10);
+             uLCD.printf("Bluetooth override OFF   ");
+             uLCD_mutex.unlock();
+             if(tempF > 75.0){
+                 mymotor.write(1);
+                 uLCD_mutex.lock();
+                 uLCD.locate(0,5);
+                 uLCD.printf("Fan is ON   ");  
+                 uLCD_mutex.unlock();        
+             }
+             else {
+                 mymotor.write(0); 
+                 uLCD_mutex.lock();
+                 uLCD.locate(0,5);
+                 uLCD.printf("Fan is OFF   ");
+                 uLCD_mutex.unlock();
+             }
+          }
+          else if(bnum == '2'){
+                 led1 = 0;
+                 led2 = 1;
+                 led3 = 0;
+                 mymotor.write(1);
+                 uLCD_mutex.lock();
+                 uLCD.locate(0,5);
+                 uLCD.printf("Fan is ON   ");
+                 uLCD.locate(0,10);
+                 uLCD.printf("Bluetooth override ON   ");
+                 uLCD_mutex.unlock();
+          }
+          else if(bnum == '3'){
+                 led1 = 0;
+                 led2 = 0;
+                 led3 = 1;
+                 mymotor.write(0); 
+                 uLCD_mutex.lock();
+                 uLCD.locate(0,5);
+                 uLCD.printf("Fan is OFF   ");
+                 uLCD.locate(0,10);
+                 uLCD.printf("Bluetooth override ON   ");
+                 uLCD_mutex.unlock();
+          }
+          if (blue.getc()=='!') {
+            if (blue.getc()=='B') { //button data
+                bnum = blue.getc(); //button number
+            }
+          }
+     }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue Mar 14 19:26:45 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Mar 14 19:26:45 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90
\ No newline at end of file