![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All tasks complete
Dependencies: mbed MCP23017 mbed-rtos WattBob_TextLCD
Diff: assignment3tasks.cpp
- Revision:
- 6:abbd51d9b045
- Parent:
- 5:f5dda79b93cb
- Child:
- 7:87f7ba90fdce
--- a/assignment3tasks.cpp Tue Mar 26 15:20:57 2019 +0000 +++ b/assignment3tasks.cpp Tue Mar 26 16:20:28 2019 +0000 @@ -47,21 +47,42 @@ void task1readbrake() -{ +{ + float delay = 1000 / TASKFREQ1; + while(true){ + speedXS.lock();//lock + speed.brakevalue = brake_pedal.read(); + speedXS.unlock();//unlock + + Thread::wait( (int) delay); + + } } void task2readaccel() { + float delay = 1000 / TASKFREQ2; + while(true){ + speedXS.lock();//lock + speed.accelvalue = accel_pedal.read(); + speedXS.unlock();//unlock + + Thread::wait( (int) delay); + + } + } void task3enginestate() -{ +{ + float delay = 1000 / TASKFREQ3; + while(true){ //lock carstateXS.lock(); uint8_t engineonoff = ngene.read(); @@ -75,20 +96,44 @@ else{ ngeneind = 0; } + + Thread::wait( (int) delay); + } } void task4average() { - //lock + float delay = 1000 / TASKFREQ4; + while(true){ + speedXS.lock();//lock - for(int i = 0; i < SAMPLESIZE ; i++){ + for(int i = 0; i < SAMPLESIZE ; i++) //speed.raw = (speed.accelvalue - speed.brakevalue)*MAXSPEED; speed.average += speed.array[i]; - speed.average = (speed.average / SAMPLESIZE); - - + speed.average = (speed.average / SAMPLESIZE); + + speedXS.unlock();//unlock + + Thread::wait( (int) delay); + } +} + +void task5brakeLED() +{ + float delay = 1000 / TASKFREQ5; + while(true){ - } + //lock + speedXS.lock(); + float braketest = speed.brakevalue; + + speedXS.unlock();//unlock + + if( braketest > 0.2) // speed increase + brakeind = 1; + else + brakeind = 0; - //unlock + Thread::wait((int)delay); + } } \ No newline at end of file