Example software of using the mbed-rtos to control a simple vehicle's on board computer

Dependencies:   MCP23017 WattBob_TextLCD mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
sk398
Date:
Mon Mar 21 13:57:22 2016 +0000
Child:
1:cdf851858518
Commit message:
Initial commit. 2 threads running correctly. Think the Mutex works well but not sure how to text

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /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);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Mon Mar 21 13:57:22 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#dfc27975e193
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 21 13:57:22 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb
\ No newline at end of file