AC with Bluetooth Control

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

Committer:
fmaxwell6
Date:
Tue Mar 14 19:26:45 2017 +0000
Revision:
0:d185280d778b
AC controlled with bluetooth

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fmaxwell6 0:d185280d778b 1 #include "mbed.h"
fmaxwell6 0:d185280d778b 2 #include "uLCD_4DGL.h"
fmaxwell6 0:d185280d778b 3 #include "TMP36.h"
fmaxwell6 0:d185280d778b 4 #include "rtos.h"
fmaxwell6 0:d185280d778b 5 uLCD_4DGL uLCD(p28, p27, p30); // serial tx, serial rx, reset pin;
fmaxwell6 0:d185280d778b 6 TMP36 myTMP36(p15);
fmaxwell6 0:d185280d778b 7 DigitalOut Ctrl(p21);
fmaxwell6 0:d185280d778b 8 DigitalOut led1(LED1);
fmaxwell6 0:d185280d778b 9 DigitalOut led2(LED2);
fmaxwell6 0:d185280d778b 10 DigitalOut led3(LED3);
fmaxwell6 0:d185280d778b 11 PwmOut mymotor(p22);
fmaxwell6 0:d185280d778b 12 RawSerial blue(p9,p10);
fmaxwell6 0:d185280d778b 13 Mutex uLCD_mutex;
fmaxwell6 0:d185280d778b 14
fmaxwell6 0:d185280d778b 15 double speed = 0.0;
fmaxwell6 0:d185280d778b 16 float tempC, tempF;
fmaxwell6 0:d185280d778b 17
fmaxwell6 0:d185280d778b 18 void Tempature_thread(){
fmaxwell6 0:d185280d778b 19 while(1){
fmaxwell6 0:d185280d778b 20 tempC = myTMP36.read();
fmaxwell6 0:d185280d778b 21 //convert to degrees F
fmaxwell6 0:d185280d778b 22 tempF = (9.0*tempC)/5.0 + 32.0;
fmaxwell6 0:d185280d778b 23 uLCD_mutex.lock();
fmaxwell6 0:d185280d778b 24 uLCD.locate(0,0);
fmaxwell6 0:d185280d778b 25 uLCD.printf("The Temperature is: %3.1f F \n", tempF);
fmaxwell6 0:d185280d778b 26 uLCD_mutex.unlock();
fmaxwell6 0:d185280d778b 27 wait(1);
fmaxwell6 0:d185280d778b 28 }
fmaxwell6 0:d185280d778b 29 }
fmaxwell6 0:d185280d778b 30 int main()
fmaxwell6 0:d185280d778b 31 {
fmaxwell6 0:d185280d778b 32 blue.baud(9600);
fmaxwell6 0:d185280d778b 33 char bnum='1';
fmaxwell6 0:d185280d778b 34 Ctrl = 1;
fmaxwell6 0:d185280d778b 35 uLCD.reset();
fmaxwell6 0:d185280d778b 36 Thread t0;
fmaxwell6 0:d185280d778b 37 t0.start(Tempature_thread);
fmaxwell6 0:d185280d778b 38 while(1)
fmaxwell6 0:d185280d778b 39 {
fmaxwell6 0:d185280d778b 40 if(bnum == '1'){
fmaxwell6 0:d185280d778b 41 led1 = 1;
fmaxwell6 0:d185280d778b 42 led2 = 0;
fmaxwell6 0:d185280d778b 43 led3 = 0;
fmaxwell6 0:d185280d778b 44 uLCD_mutex.lock();
fmaxwell6 0:d185280d778b 45 uLCD.locate(0,10);
fmaxwell6 0:d185280d778b 46 uLCD.printf("Bluetooth override OFF ");
fmaxwell6 0:d185280d778b 47 uLCD_mutex.unlock();
fmaxwell6 0:d185280d778b 48 if(tempF > 75.0){
fmaxwell6 0:d185280d778b 49 mymotor.write(1);
fmaxwell6 0:d185280d778b 50 uLCD_mutex.lock();
fmaxwell6 0:d185280d778b 51 uLCD.locate(0,5);
fmaxwell6 0:d185280d778b 52 uLCD.printf("Fan is ON ");
fmaxwell6 0:d185280d778b 53 uLCD_mutex.unlock();
fmaxwell6 0:d185280d778b 54 }
fmaxwell6 0:d185280d778b 55 else {
fmaxwell6 0:d185280d778b 56 mymotor.write(0);
fmaxwell6 0:d185280d778b 57 uLCD_mutex.lock();
fmaxwell6 0:d185280d778b 58 uLCD.locate(0,5);
fmaxwell6 0:d185280d778b 59 uLCD.printf("Fan is OFF ");
fmaxwell6 0:d185280d778b 60 uLCD_mutex.unlock();
fmaxwell6 0:d185280d778b 61 }
fmaxwell6 0:d185280d778b 62 }
fmaxwell6 0:d185280d778b 63 else if(bnum == '2'){
fmaxwell6 0:d185280d778b 64 led1 = 0;
fmaxwell6 0:d185280d778b 65 led2 = 1;
fmaxwell6 0:d185280d778b 66 led3 = 0;
fmaxwell6 0:d185280d778b 67 mymotor.write(1);
fmaxwell6 0:d185280d778b 68 uLCD_mutex.lock();
fmaxwell6 0:d185280d778b 69 uLCD.locate(0,5);
fmaxwell6 0:d185280d778b 70 uLCD.printf("Fan is ON ");
fmaxwell6 0:d185280d778b 71 uLCD.locate(0,10);
fmaxwell6 0:d185280d778b 72 uLCD.printf("Bluetooth override ON ");
fmaxwell6 0:d185280d778b 73 uLCD_mutex.unlock();
fmaxwell6 0:d185280d778b 74 }
fmaxwell6 0:d185280d778b 75 else if(bnum == '3'){
fmaxwell6 0:d185280d778b 76 led1 = 0;
fmaxwell6 0:d185280d778b 77 led2 = 0;
fmaxwell6 0:d185280d778b 78 led3 = 1;
fmaxwell6 0:d185280d778b 79 mymotor.write(0);
fmaxwell6 0:d185280d778b 80 uLCD_mutex.lock();
fmaxwell6 0:d185280d778b 81 uLCD.locate(0,5);
fmaxwell6 0:d185280d778b 82 uLCD.printf("Fan is OFF ");
fmaxwell6 0:d185280d778b 83 uLCD.locate(0,10);
fmaxwell6 0:d185280d778b 84 uLCD.printf("Bluetooth override ON ");
fmaxwell6 0:d185280d778b 85 uLCD_mutex.unlock();
fmaxwell6 0:d185280d778b 86 }
fmaxwell6 0:d185280d778b 87 if (blue.getc()=='!') {
fmaxwell6 0:d185280d778b 88 if (blue.getc()=='B') { //button data
fmaxwell6 0:d185280d778b 89 bnum = blue.getc(); //button number
fmaxwell6 0:d185280d778b 90 }
fmaxwell6 0:d185280d778b 91 }
fmaxwell6 0:d185280d778b 92 }
fmaxwell6 0:d185280d778b 93 }