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

Dependencies:   MCP23017 WattBob_TextLCD mbed-rtos mbed

main.cpp

Committer:
sk398
Date:
2016-03-29
Revision:
1:cdf851858518
Parent:
0:f7d6ed1dfe3e
Child:
2:13a9394ba2e0

File content as of revision 1:cdf851858518:

#include "mbed.h"
#include "rtos.h"

#define TRUE 1
#define FALSE 0

AnalogIn Brake(p19);
AnalogIn Accelerometer(p20);

DigitalIn EngineState(p18);
DigitalIn LeftIndicator(p17);
DigitalIn RightIndicator(p16);
DigitalIn SideLightIndicator(p15);

DigitalOut EngineStateInd(LED1);
DigitalOut SideLightInd(LED2);

PwmOut LeftLightInd(LED3);
PwmOut RightLightInd(LED4);
PwmOut OverSpeedInd(p21);


void Task8_ReadSideLight(void const *arg)
{
    if(SideLightIndicator)
    {
        SideLightInd = TRUE;
    }
    else
    {
        SideLightInd = FALSE;  
    }  
}

void Task9_ReadIndicatorLights(void const *arg)
{
    // Left Indicator Only
    if(LeftIndicator && !RightIndicator)
    {
        LeftIndicator.period(1.0);
        LeftIndicator.pulsewidth(0.5);
    }
    
    // Right Indicator Only
    else if(!LeftIndicator && RightIndicator)
    {
        RightIndicator.period(1.0);
        RightIndicator.pulsewidth(0.5);
    }
    
    // Left and Right Indicators
    else if(LeftIndicator && RightIndicator)
    {
        LeftIndicator.period(0.5);
        RightIndicator.period(0.5);
        
        LeftIndicator.pulsewidth(0.25);
        RightIndicator.pulsewidth(0.25);
    }
}
        

int main()
{
 
 RtosTimer Task8(Task8_ReadSideLight,osTimerPeriodic); 
 RtosTimer Task9(Task9_ReadIndicatorLights,osTimerPeriodic);
 
 Task8.start(1000);
 Task9.start(2000);
 
 Thread::wait(osWaitForever);
    
    
}

//
//
//Mutex readvalues;
//Semaphore read_s(1);
//
//Mail<value_t, 100> mail_box;
//
//
//float readValue = 1.0;
//
//typedef struct
//{
//    float AccelerationRaw;
//    float BrakeRaw;
//} value_t;
//
//
//void readAnalogPins(void const *args)
//{
//    while(1)
//    {
//        value_t *ReadValue = mail_box.alloc();
//        
//        ReadValue -> AccelerationrRaw = Accelerometer.read();
//        ReadValue -> BrakeRaw = Brake.read();
//        
//        mail_box.put(ReadValue);
//        Thread::wait(100); 
//    }
//    
//}
//
//void sendToPC(void const *args)
//{
//    while(1)
//    {
//        osEvent evt = mail_box.get();
//        
//        if(evt.status == osEventMail)
//        {
//            value_t *ReadValue = (value_t*)evt.value.p;
//            printf("Value: %1.3f\r\n", ReadValue-> vale);
//            mail_box.free(ReadValue);
//        }
//        Thread::wait(5000); 
//    }
//    
//}
//
//int main() {
//    
//    Thread thread_1(readData);    
//    Thread thread_2(sendToPC);
//    
//    while(1) {
//        
//        myled = 1;
//        wait(0.2);
//        myled = 0;
//        wait(0.2);
//    }
//}