Example software of using the mbed-rtos to control a simple vehicle's on board computer
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
Diff: main.cpp
- Revision:
- 0:f7d6ed1dfe3e
- Child:
- 1:cdf851858518
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Mar 21 13:57:22 2016 +0000 @@ -0,0 +1,67 @@ +#include "mbed.h" +#include "rtos.h" + +DigitalOut myled(LED1); +AnalogIn Accelerometer(p20); + +Mutex readvalues; +Semaphore read_s(1); + + +float readValue = 1.0; + +typedef struct +{ + float value; +} value_t; + +void thread1(void const *args) +{ + while(1) + { +// read_s.wait(); + value_t *mail = mail_box.alloc(); + + readvalues.lock(); + value_t -> value = Accelerometer.read(); + readvalues.unlock(); +// read_s.release(); +// printf("hello-1 = %1.3f\r\n",readValue); + Thread::wait(1000); + } + +} + +void thread2(void const *args) +{ + while(1) + { + readvalues.lock(); +// read_s.wait(); + printf("readValue = %s\r\n",(const char*)args); +// read_s.release(); + readvalues.unlock(); + Thread::wait(500); + } + +} + +int main() { + char array[10]; + + Thread thread_1(thread1); + Thread thread_2(thread2,(void *)array); + + while(1) { + + readvalues.lock(); + int var = sprintf(array,"%1.3f",readValue); + printf("%s\r\n",array); + readvalues.unlock(); + + myled = 1; + wait(0.2); + myled = 0; + wait(0.2); + } +}