Code for Sprint 2
Dependencies: C12832 mbed rtos RangeFinder
main.cpp
- Committer:
- PaulF
- Date:
- 2015-02-26
- Revision:
- 1:28ea653772dc
- Parent:
- 0:5edc27224a37
- Child:
- 2:b109a4eb9b0d
File content as of revision 1:28ea653772dc:
#include "mbed.h" #include "rtos.h" #include "Servo.h" #include "C12832.h" Servo s1(p21); Servo s2(p22); Serial pc(USBTX, USBRX); Mutex mutexIn; Mutex mutexOut; // Globel variables char cordinates[3]; char corHoriz; char corVertic; //float corDeep; //float outVert; //float outHoriz; C12832 lcd(p5, p7, p6, p8, p11);// lcd is an object from class c12832 initialised by p5,p7.... /* Thread Serial 1 - handles the output data from the control thread, and pass to the servo. @update s1, s2 */ void serial_thread(void const *args) { while (true) { mutexIn.lock(); pc.gets(cordinates,2); // cordinates = pc.putc(pc.getc()); corHoriz = cordinates[0]; corVertic = cordinates[1]; // corDeep = cordinates[2]; mutexIn.unlock(); Thread::wait(200); } } /* Thread LCD 2 - handles the input data from the sonar sensor, and display on the LCD screen. @update inData */ void lcd_thread(void const *args) { while (true) { mutexIn.lock(); mutexOut.lock(); // Display values on the LCD screen lcd.cls(); // clear the display lcd.locate(0,3); // the location where you want your charater to be displayed lcd.printf("Hor: %c, Vert: %c, ", corHoriz, corVertic ); mutexIn.unlock(); mutexOut.unlock(); Thread::wait(25); } } /* Thread Control 3 - handles the input data from the sonar sensor, and display on the LCD screen. @update inData */ void control_thread(void const *args) { while (true) { mutexIn.lock(); // The control code will come here mutexIn.unlock(); Thread::wait(25); } } /* Thread Servo 4 - handles the output data from the control thread, and pass to the servo. @update s1, s2 */ void servo_thread(void const *args) { while (true) { mutexOut.lock(); // s1 = outVert; // s2 = outHoriz; mutexOut.unlock(); Thread::wait(200); } } int main() { Thread thread_1(serial_thread); // Start Serial Thread Thread thread_2(lcd_thread); // Start LCD Thread Thread thread_3(control_thread); // Start Control Thread Thread thread_4(servo_thread); // Start Servo Thread while(1) { Thread::wait(10); } }