Urm didnt i write this already? Mostly same as georges code, except: buffer and sensor reads in seperate threads (Not Main) some other bits

Dependencies:   BMP280

Fork of Sample_LCD_Serial_Buffer by BDG

Committer:
benparkes
Date:
Tue Dec 12 17:05:59 2017 +0000
Revision:
0:cb3a5c15b01e
Child:
1:bca9993a0df3
Working No Mail que

Who changed what in which revision?

UserRevisionLine numberNew contents of line
benparkes 0:cb3a5c15b01e 1 #include "mbed.h"
benparkes 0:cb3a5c15b01e 2 #include "main.h"
benparkes 0:cb3a5c15b01e 3
benparkes 0:cb3a5c15b01e 4
benparkes 0:cb3a5c15b01e 5
benparkes 0:cb3a5c15b01e 6
benparkes 0:cb3a5c15b01e 7 LCD lcd(PD_15, PF_12, PF_13, PE_9, PF_14, PF_15);
benparkes 0:cb3a5c15b01e 8
benparkes 0:cb3a5c15b01e 9 BMP280 Sensor(D14, D15);
benparkes 0:cb3a5c15b01e 10 void PrintLCD ();
benparkes 0:cb3a5c15b01e 11
benparkes 0:cb3a5c15b01e 12
benparkes 0:cb3a5c15b01e 13
benparkes 0:cb3a5c15b01e 14 float LDR_Value;
benparkes 0:cb3a5c15b01e 15 float temp_Value;
benparkes 0:cb3a5c15b01e 16 float press_Value;
benparkes 0:cb3a5c15b01e 17 Thread t1;
benparkes 0:cb3a5c15b01e 18 Thread t2;
benparkes 0:cb3a5c15b01e 19
benparkes 0:cb3a5c15b01e 20 Mutex door;
benparkes 0:cb3a5c15b01e 21
benparkes 0:cb3a5c15b01e 22 void PrintLCD () {
benparkes 0:cb3a5c15b01e 23
benparkes 0:cb3a5c15b01e 24 int i = 0;
benparkes 0:cb3a5c15b01e 25 while(1){
benparkes 0:cb3a5c15b01e 26 char DataString[16];
benparkes 0:cb3a5c15b01e 27 lcd.Clear();
benparkes 0:cb3a5c15b01e 28 lcd.RowSelect(0);
benparkes 0:cb3a5c15b01e 29
benparkes 0:cb3a5c15b01e 30 switch (i){
benparkes 0:cb3a5c15b01e 31 case 0:
benparkes 0:cb3a5c15b01e 32
benparkes 0:cb3a5c15b01e 33
benparkes 0:cb3a5c15b01e 34 sprintf(DataString,"%.4f", LDR_Value);
benparkes 0:cb3a5c15b01e 35 lcd.Write("Light Level:");
benparkes 0:cb3a5c15b01e 36 i++;
benparkes 0:cb3a5c15b01e 37 break;
benparkes 0:cb3a5c15b01e 38 case 1:
benparkes 0:cb3a5c15b01e 39
benparkes 0:cb3a5c15b01e 40
benparkes 0:cb3a5c15b01e 41 sprintf(DataString,"%2.2f", temp_Value);
benparkes 0:cb3a5c15b01e 42 lcd.Write("Temperature:");
benparkes 0:cb3a5c15b01e 43 i++;
benparkes 0:cb3a5c15b01e 44
benparkes 0:cb3a5c15b01e 45 break;
benparkes 0:cb3a5c15b01e 46
benparkes 0:cb3a5c15b01e 47 case 2:
benparkes 0:cb3a5c15b01e 48
benparkes 0:cb3a5c15b01e 49 sprintf(DataString,"%4.2f", press_Value);
benparkes 0:cb3a5c15b01e 50 lcd.Write("Pressure:");
benparkes 0:cb3a5c15b01e 51 i =0;
benparkes 0:cb3a5c15b01e 52 break;
benparkes 0:cb3a5c15b01e 53 default:
benparkes 0:cb3a5c15b01e 54 i = 0;
benparkes 0:cb3a5c15b01e 55 break;
benparkes 0:cb3a5c15b01e 56 }
benparkes 0:cb3a5c15b01e 57
benparkes 0:cb3a5c15b01e 58 lcd.RowSelect(1);
benparkes 0:cb3a5c15b01e 59 lcd.Write(DataString);
benparkes 0:cb3a5c15b01e 60 Thread::wait (5000);
benparkes 0:cb3a5c15b01e 61 }
benparkes 0:cb3a5c15b01e 62 }
benparkes 0:cb3a5c15b01e 63
benparkes 0:cb3a5c15b01e 64
benparkes 0:cb3a5c15b01e 65 int main() {
benparkes 0:cb3a5c15b01e 66
benparkes 0:cb3a5c15b01e 67 t1.start(PrintLCD);
benparkes 0:cb3a5c15b01e 68
benparkes 0:cb3a5c15b01e 69 while(1) {
benparkes 0:cb3a5c15b01e 70 Green_int = 1;
benparkes 0:cb3a5c15b01e 71
benparkes 0:cb3a5c15b01e 72
benparkes 0:cb3a5c15b01e 73 door.lock();
benparkes 0:cb3a5c15b01e 74
benparkes 0:cb3a5c15b01e 75 LDR_Value = LDR_In.read();
benparkes 0:cb3a5c15b01e 76 temp_Value = Sensor.getTemperature();
benparkes 0:cb3a5c15b01e 77 press_Value = Sensor.getPressure();
benparkes 0:cb3a5c15b01e 78 door.unlock();
benparkes 0:cb3a5c15b01e 79
benparkes 0:cb3a5c15b01e 80
benparkes 0:cb3a5c15b01e 81 Thread::wait (15000);
benparkes 0:cb3a5c15b01e 82 }
benparkes 0:cb3a5c15b01e 83
benparkes 0:cb3a5c15b01e 84 }
benparkes 0:cb3a5c15b01e 85
benparkes 0:cb3a5c15b01e 86 /*int main(void){
benparkes 0:cb3a5c15b01e 87
benparkes 0:cb3a5c15b01e 88 float temp = 0;
benparkes 0:cb3a5c15b01e 89 //float pressure = 0;
benparkes 0:cb3a5c15b01e 90 char tempString[16];
benparkes 0:cb3a5c15b01e 91 Sensor->initialize();
benparkes 0:cb3a5c15b01e 92 temp = Sensor->getTemperature();
benparkes 0:cb3a5c15b01e 93 lcd->Clear();
benparkes 0:cb3a5c15b01e 94 lcd->RowSelect(0);
benparkes 0:cb3a5c15b01e 95 lcd->Write("Temperature:");
benparkes 0:cb3a5c15b01e 96 sprintf(tempString,"%f",temp);
benparkes 0:cb3a5c15b01e 97 lcd->RowSelect(1);
benparkes 0:cb3a5c15b01e 98 lcd->Write(tempString);
benparkes 0:cb3a5c15b01e 99
benparkes 0:cb3a5c15b01e 100 }*/