updated codes lads

Dependencies:   C12832 Servo mbed-rtos mbed

Fork of rtos_basic_team by WIT_EmbOS_Gr1

Committer:
Ali_taher
Date:
Wed Jan 28 22:48:45 2015 +0000
Revision:
9:f60eeadabcb0
Parent:
8:507111cc659c
Child:
10:372c5d608b5c
agreed program;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:491820ee784d 1 #include "mbed.h"
emilmont 1:491820ee784d 2 #include "rtos.h"
PaulF 7:c8e192e2c80c 3 #include "Servo.h"
Ali_taher 8:507111cc659c 4 #include "C12832.h"
PaulF 7:c8e192e2c80c 5 Servo s1(p21);
PaulF 7:c8e192e2c80c 6 Servo s2(p22);
emilmont 1:491820ee784d 7
PaulF 7:c8e192e2c80c 8 AnalogIn p1(p17);
Ali_taher 9:f60eeadabcb0 9 //AnalogIn p2(p20);
Ali_taher 9:f60eeadabcb0 10 Mutex dataIn_mutex;
Ali_taher 9:f60eeadabcb0 11 Mutex dataOut_mutex;
Ali_taher 9:f60eeadabcb0 12
Ali_taher 9:f60eeadabcb0 13 // Globel variables
Ali_taher 9:f60eeadabcb0 14 float input_data;
Ali_taher 9:f60eeadabcb0 15 float output_data;
Ali_taher 9:f60eeadabcb0 16
Ali_taher 8:507111cc659c 17 C12832 lcd(p5, p7, p6, p8, p11);// lcd is an object from class c12832 initialised by p5,p7....
PaulF 7:c8e192e2c80c 18
Ali_taher 9:f60eeadabcb0 19 void sonar_thread(void const *args) {
Ali_taher 9:f60eeadabcb0 20 while (true) {
Ali_taher 9:f60eeadabcb0 21 dataIn_mutex.lock();
Ali_taher 9:f60eeadabcb0 22 input_data= p1.read()*5;
Ali_taher 9:f60eeadabcb0 23 lcd.cls(); // clear the display
Ali_taher 9:f60eeadabcb0 24 lcd.locate(0,3);// the location where you want your charater to be displayed
Ali_taher 9:f60eeadabcb0 25 lcd.printf("Thread one = %f\n", input_data);
Ali_taher 9:f60eeadabcb0 26 dataIn_mutex.unlock();
Ali_taher 9:f60eeadabcb0 27 Thread::wait(25);
Ali_taher 9:f60eeadabcb0 28 }
Ali_taher 9:f60eeadabcb0 29 }
Ali_taher 9:f60eeadabcb0 30
Ali_taher 9:f60eeadabcb0 31 void control_thread(void const *args) {
emilmont 1:491820ee784d 32 while (true) {
Ali_taher 9:f60eeadabcb0 33 dataIn_mutex.lock();
Ali_taher 9:f60eeadabcb0 34
Ali_taher 9:f60eeadabcb0 35 if (input_data>0.8)
Ali_taher 9:f60eeadabcb0 36 {
Ali_taher 9:f60eeadabcb0 37 s2=input_data*0.2;
Ali_taher 9:f60eeadabcb0 38 }
Ali_taher 9:f60eeadabcb0 39 else if(input_data<0.8)
Ali_taher 9:f60eeadabcb0 40 {
Ali_taher 9:f60eeadabcb0 41 s2=-input_data*0.5;
Ali_taher 9:f60eeadabcb0 42 }
Ali_taher 9:f60eeadabcb0 43
Ali_taher 9:f60eeadabcb0 44 s1=input_data;
Ali_taher 9:f60eeadabcb0 45
Ali_taher 9:f60eeadabcb0 46 dataIn_mutex.unlock();
Ali_taher 9:f60eeadabcb0 47 Thread::wait(20);
emilmont 1:491820ee784d 48 }
emilmont 1:491820ee784d 49 }
emilmont 1:491820ee784d 50
emilmont 1:491820ee784d 51 int main() {
Ali_taher 9:f60eeadabcb0 52 Thread thread(sonar_thread);
Ali_taher 9:f60eeadabcb0 53 Thread thread_1(control_thread);
Ali_taher 9:f60eeadabcb0 54
emilmont 1:491820ee784d 55 while (true) {
Ali_taher 9:f60eeadabcb0 56
Ali_taher 9:f60eeadabcb0 57
Ali_taher 9:f60eeadabcb0 58 Thread::wait(10);
emilmont 1:491820ee784d 59 }
emilmont 1:491820ee784d 60 }