updated codes lads

Dependencies:   C12832 Servo mbed-rtos mbed

Fork of rtos_basic_team by WIT_EmbOS_Gr1

Revision:
9:f60eeadabcb0
Parent:
8:507111cc659c
Child:
10:372c5d608b5c
diff -r 507111cc659c -r f60eeadabcb0 main.cpp
--- a/main.cpp	Mon Jan 19 20:41:15 2015 +0000
+++ b/main.cpp	Wed Jan 28 22:48:45 2015 +0000
@@ -6,26 +6,55 @@
 Servo s2(p22);
  
 AnalogIn p1(p17);
-AnalogIn p2(p20); 
+//AnalogIn p2(p20); 
+Mutex dataIn_mutex;
+Mutex dataOut_mutex;
+
+// Globel variables 
+float input_data;
+float output_data;
+
 C12832 lcd(p5, p7, p6, p8, p11);// lcd is an object from class c12832 initialised by p5,p7....
  
-void p2_thread(void const *args) {
+void sonar_thread(void const *args) {
+    while (true) {
+            dataIn_mutex.lock();
+            input_data= p1.read()*5;
+            lcd.cls();      // clear the display
+            lcd.locate(0,3);// the location where you want your charater to be displayed
+            lcd.printf("Thread one = %f\n", input_data);
+            dataIn_mutex.unlock();
+            Thread::wait(25);
+    }
+}
+ 
+ void control_thread(void const *args) {
     while (true) {
-            s2 = p1*5;
-            lcd.cls();  // clear the display
-            lcd.locate(0,3);// the location where you want your charater to be displayed
-            lcd.printf("Thread one = %f\n", (float)p1*5);
-             Thread::wait(1500);
+            dataIn_mutex.lock();
+            
+           if (input_data>0.8)
+         {
+            s2=input_data*0.2;
+            }
+            else if(input_data<0.8)
+            {
+            s2=-input_data*0.5;
+            }
+             
+     s1=input_data;
+    
+            dataIn_mutex.unlock();
+            Thread::wait(20);
     }
 }
  
 int main() {
-    Thread thread(p2_thread); 
+    Thread thread(sonar_thread);
+    Thread thread_1(control_thread);
+    
     while (true) {
-         lcd.cls(); // clear the display
-        lcd.locate(0,15);   // the location where you want your charater to be displayed
-         lcd.printf("Thread two = %f\n", (float)p2*5);
-        s1 = p1*5;
-        Thread::wait(1000);
+         
+        
+        Thread::wait(10);
     }
 }