Code for Sprint 2

Dependencies:   C12832 mbed rtos RangeFinder

main.cpp

Committer:
Argensis
Date:
2015-04-13
Revision:
9:e5d24b7a921b
Parent:
4:70090f3b1f07
Child:
10:ca6f2769964e

File content as of revision 9:e5d24b7a921b:

#include "mbed.h"
#include "rtos.h"
#include "Servo.h"
#include "C12832.h"

Servo tiltServo(p21);
Servo panServo(p22);
Serial pc(USBTX, USBRX);
Mutex mutexIn;
Mutex mutexOut;
 
AnalogIn p1(p19);
AnalogIn p2(p20);

// Global variables
float corHoriz = 0;
float corVert = 0;
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) {
        pc.scanf("%f,%f", &corHoriz, &corVert);// read from serial port the data
    }
}
 
/* 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) {
        // Display values on the LCD screen
        lcd.cls();          // clear the display
        lcd.locate(0,5);    // the location where you want your charater to be displayed
        lcd.printf("Hor: %0.3f", corHoriz);
        lcd.locate(0,20);    // the location where you want your charater to be displayed
        lcd.printf("Ver: %0.3f", corVert);
        Thread::wait(250);
    }
}

/* Thread Servo 3 - handles the output data from the control thread, and pass to the servo.
    @update s1, s2 */
void servo_thread(void const *args) {
    while (true) {
        tiltServo = corVert;
        panServo = corHoriz;
        Thread::wait(200);
    }
}

int main() {
    Thread thread_1(serial_thread); // Start Serial Thread
    Thread thread_2(lcd_thread); // Start LCD Thread
    Thread thread_3(servo_thread); // Start Servo Thread
    while(1) {
        wait(1);
    }
}