Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Thread_Communication_V4_fortest by
main.cpp
- Committer:
- benparkes
- Date:
- 2017-12-13
- Revision:
- 1:bca9993a0df3
- Parent:
- 0:cb3a5c15b01e
- Child:
- 2:28d12a3db239
File content as of revision 1:bca9993a0df3:
#include "mbed.h" #include "main.h" LCD lcd(PD_15, PF_12, PF_13, PE_9, PF_14, PF_15); BMP280 Sensor(D14, D15); void PrintLCD (); /* Mail */ typedef struct { float LDR_Value; float temp_Value; float press_Value; } mail_t; //Class type /*class mail_t { public: float LDR_Value; float temp_Value; float press_Value; //Constructor mail_t( float LDR_Value, float temp_Value, int s2) { adcValue = f; sw1State = s1; sw2State = s2; } };*/ Mail<mail_t, 16> mail_box; Thread t1; Thread t2; //Mutex door; void PrintLCD () { int i = 0; while(1){ char lightString[16]; char tempString[16]; char pressString[16]; lcd.Clear(); lcd.RowSelect(0); switch (i){ case 0: osEvent evt = mail_box.get(); if (evt.status == osEventMail) { mail_t *mail = (mail_t*)evt.value.p; sprintf(lightString,"%.4f", mail->LDR_Value); sprintf(tempString,"%2.2f", mail->temp_Value); sprintf(pressString,"%4.2f", mail->press_Value); mail_box.free(mail); } lcd.Write("Light Level:"); lcd.RowSelect(1); lcd.Write(lightString); i++; break; case 1: lcd.Write("Temperature:"); lcd.RowSelect(1); lcd.Write(tempString); i++; break; case 2: lcd.Write("Pressure:"); lcd.RowSelect(1); lcd.Write(pressString); i =0; break; default: i = 0; break; } Red_int = !Red_int; Thread::wait (5000); } } int main() { t1.start(PrintLCD); while(1) { Green_int = !Green_int; mail_t *mail = mail_box.alloc(); mail->LDR_Value = LDR_In.read(); mail->temp_Value = Sensor.getTemperature(); mail->press_Value = Sensor.getPressure(); mail_box.put(mail); /*door.lock(); LDR_Value = LDR_In.read(); temp_Value = Sensor.getTemperature(); press_Value = Sensor.getPressure(); door.unlock();*/ Thread::wait (15000); } } /*int main(void){ float temp = 0; //float pressure = 0; char tempString[16]; Sensor->initialize(); temp = Sensor->getTemperature(); lcd->Clear(); lcd->RowSelect(0); lcd->Write("Temperature:"); sprintf(tempString,"%f",temp); lcd->RowSelect(1); lcd->Write(tempString); }*/