Buffer working with LCD, Serial and SD Card

Dependencies:   BMP280

Fork of Thread_Communication by BDG

Committer:
benparkes
Date:
Wed Dec 13 17:20:18 2017 +0000
Revision:
1:bca9993a0df3
Parent:
0:cb3a5c15b01e
Child:
2:28d12a3db239
15s Measurement and print working;

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 1:bca9993a0df3 12 /* Mail */
benparkes 1:bca9993a0df3 13 typedef struct {
benparkes 1:bca9993a0df3 14 float LDR_Value;
benparkes 1:bca9993a0df3 15 float temp_Value;
benparkes 1:bca9993a0df3 16 float press_Value;
benparkes 1:bca9993a0df3 17 } mail_t;
benparkes 1:bca9993a0df3 18
benparkes 1:bca9993a0df3 19 //Class type
benparkes 1:bca9993a0df3 20 /*class mail_t {
benparkes 1:bca9993a0df3 21 public:
benparkes 1:bca9993a0df3 22 float LDR_Value;
benparkes 1:bca9993a0df3 23 float temp_Value;
benparkes 1:bca9993a0df3 24 float press_Value;
benparkes 1:bca9993a0df3 25
benparkes 1:bca9993a0df3 26 //Constructor
benparkes 1:bca9993a0df3 27 mail_t( float LDR_Value, float temp_Value, int s2) {
benparkes 1:bca9993a0df3 28 adcValue = f;
benparkes 1:bca9993a0df3 29 sw1State = s1;
benparkes 1:bca9993a0df3 30 sw2State = s2;
benparkes 1:bca9993a0df3 31 }
benparkes 1:bca9993a0df3 32 };*/
benparkes 1:bca9993a0df3 33
benparkes 1:bca9993a0df3 34 Mail<mail_t, 16> mail_box;
benparkes 0:cb3a5c15b01e 35
benparkes 0:cb3a5c15b01e 36
benparkes 0:cb3a5c15b01e 37 Thread t1;
benparkes 0:cb3a5c15b01e 38 Thread t2;
benparkes 0:cb3a5c15b01e 39
benparkes 1:bca9993a0df3 40 //Mutex door;
benparkes 0:cb3a5c15b01e 41
benparkes 0:cb3a5c15b01e 42 void PrintLCD () {
benparkes 0:cb3a5c15b01e 43
benparkes 0:cb3a5c15b01e 44 int i = 0;
benparkes 0:cb3a5c15b01e 45 while(1){
benparkes 1:bca9993a0df3 46 char lightString[16];
benparkes 1:bca9993a0df3 47 char tempString[16];
benparkes 1:bca9993a0df3 48 char pressString[16];
benparkes 1:bca9993a0df3 49
benparkes 1:bca9993a0df3 50
benparkes 0:cb3a5c15b01e 51 lcd.Clear();
benparkes 0:cb3a5c15b01e 52 lcd.RowSelect(0);
benparkes 1:bca9993a0df3 53
benparkes 0:cb3a5c15b01e 54 switch (i){
benparkes 1:bca9993a0df3 55 case 0:
benparkes 1:bca9993a0df3 56 osEvent evt = mail_box.get();
benparkes 1:bca9993a0df3 57
benparkes 1:bca9993a0df3 58 if (evt.status == osEventMail) {
benparkes 1:bca9993a0df3 59 mail_t *mail = (mail_t*)evt.value.p;
benparkes 0:cb3a5c15b01e 60
benparkes 1:bca9993a0df3 61 sprintf(lightString,"%.4f", mail->LDR_Value);
benparkes 1:bca9993a0df3 62 sprintf(tempString,"%2.2f", mail->temp_Value);
benparkes 1:bca9993a0df3 63 sprintf(pressString,"%4.2f", mail->press_Value);
benparkes 1:bca9993a0df3 64
benparkes 1:bca9993a0df3 65 mail_box.free(mail);
benparkes 1:bca9993a0df3 66 }
benparkes 1:bca9993a0df3 67
benparkes 1:bca9993a0df3 68 lcd.Write("Light Level:");
benparkes 1:bca9993a0df3 69 lcd.RowSelect(1);
benparkes 1:bca9993a0df3 70 lcd.Write(lightString);
benparkes 1:bca9993a0df3 71 i++;
benparkes 0:cb3a5c15b01e 72
benparkes 0:cb3a5c15b01e 73 break;
benparkes 0:cb3a5c15b01e 74 case 1:
benparkes 1:bca9993a0df3 75
benparkes 0:cb3a5c15b01e 76 lcd.Write("Temperature:");
benparkes 1:bca9993a0df3 77 lcd.RowSelect(1);
benparkes 1:bca9993a0df3 78 lcd.Write(tempString);
benparkes 0:cb3a5c15b01e 79 i++;
benparkes 0:cb3a5c15b01e 80
benparkes 0:cb3a5c15b01e 81 break;
benparkes 0:cb3a5c15b01e 82
benparkes 0:cb3a5c15b01e 83 case 2:
benparkes 1:bca9993a0df3 84
benparkes 0:cb3a5c15b01e 85 lcd.Write("Pressure:");
benparkes 1:bca9993a0df3 86 lcd.RowSelect(1);
benparkes 1:bca9993a0df3 87 lcd.Write(pressString);
benparkes 0:cb3a5c15b01e 88 i =0;
benparkes 0:cb3a5c15b01e 89 break;
benparkes 0:cb3a5c15b01e 90 default:
benparkes 0:cb3a5c15b01e 91 i = 0;
benparkes 0:cb3a5c15b01e 92 break;
benparkes 0:cb3a5c15b01e 93 }
benparkes 1:bca9993a0df3 94 Red_int = !Red_int;
benparkes 0:cb3a5c15b01e 95
benparkes 1:bca9993a0df3 96
benparkes 1:bca9993a0df3 97
benparkes 0:cb3a5c15b01e 98 Thread::wait (5000);
benparkes 0:cb3a5c15b01e 99 }
benparkes 0:cb3a5c15b01e 100 }
benparkes 0:cb3a5c15b01e 101
benparkes 0:cb3a5c15b01e 102
benparkes 0:cb3a5c15b01e 103 int main() {
benparkes 0:cb3a5c15b01e 104
benparkes 0:cb3a5c15b01e 105 t1.start(PrintLCD);
benparkes 1:bca9993a0df3 106
benparkes 0:cb3a5c15b01e 107 while(1) {
benparkes 1:bca9993a0df3 108 Green_int = !Green_int;
benparkes 1:bca9993a0df3 109
benparkes 1:bca9993a0df3 110 mail_t *mail = mail_box.alloc();
benparkes 1:bca9993a0df3 111 mail->LDR_Value = LDR_In.read();
benparkes 1:bca9993a0df3 112 mail->temp_Value = Sensor.getTemperature();
benparkes 1:bca9993a0df3 113 mail->press_Value = Sensor.getPressure();
benparkes 1:bca9993a0df3 114 mail_box.put(mail);
benparkes 0:cb3a5c15b01e 115
benparkes 1:bca9993a0df3 116 /*door.lock();
benparkes 0:cb3a5c15b01e 117
benparkes 0:cb3a5c15b01e 118 LDR_Value = LDR_In.read();
benparkes 0:cb3a5c15b01e 119 temp_Value = Sensor.getTemperature();
benparkes 0:cb3a5c15b01e 120 press_Value = Sensor.getPressure();
benparkes 1:bca9993a0df3 121 door.unlock();*/
benparkes 0:cb3a5c15b01e 122
benparkes 0:cb3a5c15b01e 123
benparkes 1:bca9993a0df3 124 Thread::wait (15000);
benparkes 0:cb3a5c15b01e 125 }
benparkes 0:cb3a5c15b01e 126
benparkes 0:cb3a5c15b01e 127 }
benparkes 0:cb3a5c15b01e 128
benparkes 0:cb3a5c15b01e 129 /*int main(void){
benparkes 0:cb3a5c15b01e 130
benparkes 0:cb3a5c15b01e 131 float temp = 0;
benparkes 0:cb3a5c15b01e 132 //float pressure = 0;
benparkes 0:cb3a5c15b01e 133 char tempString[16];
benparkes 0:cb3a5c15b01e 134 Sensor->initialize();
benparkes 0:cb3a5c15b01e 135 temp = Sensor->getTemperature();
benparkes 0:cb3a5c15b01e 136 lcd->Clear();
benparkes 0:cb3a5c15b01e 137 lcd->RowSelect(0);
benparkes 0:cb3a5c15b01e 138 lcd->Write("Temperature:");
benparkes 0:cb3a5c15b01e 139 sprintf(tempString,"%f",temp);
benparkes 0:cb3a5c15b01e 140 lcd->RowSelect(1);
benparkes 0:cb3a5c15b01e 141 lcd->Write(tempString);
benparkes 0:cb3a5c15b01e 142
benparkes 0:cb3a5c15b01e 143 }*/