![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All tasks complete
Dependencies: mbed MCP23017 mbed-rtos WattBob_TextLCD
assignment3tasks.cpp@3:f88d667629e6, 2019-03-25 (annotated)
- Committer:
- aingks
- Date:
- Mon Mar 25 21:13:24 2019 +0000
- Revision:
- 3:f88d667629e6
- Parent:
- 2:9d6d07c9cc9c
- Child:
- 4:27340b291c09
added the led code however ifndef is not working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aingks | 0:0943f040009c | 1 | #include "header.h" |
aingks | 3:f88d667629e6 | 2 | |
aingks | 2:9d6d07c9cc9c | 3 | |
aingks | 0:0943f040009c | 4 | //definitions of taskss |
aingks | 0:0943f040009c | 5 | //lock and unlock variables in struct whne performing calculations |
aingks | 0:0943f040009c | 6 | |
aingks | 0:0943f040009c | 7 | //pedals |
aingks | 0:0943f040009c | 8 | AnalogIn brake_pedal(pin_analog_1); |
aingks | 0:0943f040009c | 9 | AnalogIn accel_pedal(pin_analog_2); |
aingks | 0:0943f040009c | 10 | |
aingks | 0:0943f040009c | 11 | |
aingks | 0:0943f040009c | 12 | //switches |
aingks | 0:0943f040009c | 13 | DigitalIn ngene(pin_digital_1); |
aingks | 1:c4f62ef9b5b7 | 14 | DigitalIn leftsw(pin_digital_2); |
aingks | 1:c4f62ef9b5b7 | 15 | DigitalIn rightsw(pin_digital_3); |
aingks | 1:c4f62ef9b5b7 | 16 | DigitalIn sidesw(pin_digital_4); |
aingks | 0:0943f040009c | 17 | |
aingks | 0:0943f040009c | 18 | |
aingks | 0:0943f040009c | 19 | //indicators |
aingks | 0:0943f040009c | 20 | DigitalOut ngeneind(pin_LED1); |
aingks | 0:0943f040009c | 21 | DigitalOut leftind(pin_LED2); |
aingks | 0:0943f040009c | 22 | DigitalOut rightind(pin_LED3); |
aingks | 0:0943f040009c | 23 | DigitalOut sideind(pin_LED4); |
aingks | 0:0943f040009c | 24 | |
aingks | 0:0943f040009c | 25 | |
aingks | 0:0943f040009c | 26 | //RED box lights |
aingks | 0:0943f040009c | 27 | DigitalOut brakeind(pin_LED5); |
aingks | 0:0943f040009c | 28 | DigitalOut overspeedind(pin_LED6); |
aingks | 0:0943f040009c | 29 | |
aingks | 2:9d6d07c9cc9c | 30 | Mutex stdio_mutex; |
aingks | 2:9d6d07c9cc9c | 31 | |
aingks | 0:0943f040009c | 32 | |
aingks | 0:0943f040009c | 33 | void task1readbrake() |
aingks | 0:0943f040009c | 34 | { |
aingks | 2:9d6d07c9cc9c | 35 | stdio_mutex.lock();//lock |
aingks | 1:c4f62ef9b5b7 | 36 | speed.brakevalue = brake_pedal.read(); |
aingks | 2:9d6d07c9cc9c | 37 | stdio_mutex.unlock();//unlock |
aingks | 0:0943f040009c | 38 | } |
aingks | 0:0943f040009c | 39 | |
aingks | 0:0943f040009c | 40 | void task2readaccel() |
aingks | 0:0943f040009c | 41 | { |
aingks | 2:9d6d07c9cc9c | 42 | stdio_mutex.lock();//lock |
aingks | 1:c4f62ef9b5b7 | 43 | speed.accelvalue = accel_pedal.read(); |
aingks | 2:9d6d07c9cc9c | 44 | stdio_mutex.unlock();//unlock |
aingks | 0:0943f040009c | 45 | } |
aingks | 0:0943f040009c | 46 | |
aingks | 0:0943f040009c | 47 | void task3enginestate() |
aingks | 1:c4f62ef9b5b7 | 48 | { |
aingks | 1:c4f62ef9b5b7 | 49 | //lock |
aingks | 2:9d6d07c9cc9c | 50 | stdio_mutex.lock(); |
aingks | 1:c4f62ef9b5b7 | 51 | uint8_t engineonoff = ngene.read(); |
aingks | 2:9d6d07c9cc9c | 52 | info.ENGINESTATE = engineonoff; |
aingks | 2:9d6d07c9cc9c | 53 | stdio_mutex.unlock(); |
aingks | 1:c4f62ef9b5b7 | 54 | //unlock |
aingks | 1:c4f62ef9b5b7 | 55 | |
aingks | 1:c4f62ef9b5b7 | 56 | if(engineonoff == 1){ |
aingks | 1:c4f62ef9b5b7 | 57 | ngeneind = 1; |
aingks | 1:c4f62ef9b5b7 | 58 | } |
aingks | 1:c4f62ef9b5b7 | 59 | else{ |
aingks | 1:c4f62ef9b5b7 | 60 | ngeneind = 0; |
aingks | 1:c4f62ef9b5b7 | 61 | } |
aingks | 0:0943f040009c | 62 | } |
aingks | 0:0943f040009c | 63 | |
aingks | 0:0943f040009c | 64 | void task4average() |
aingks | 0:0943f040009c | 65 | { |
aingks | 0:0943f040009c | 66 | |
aingks | 0:0943f040009c | 67 | } |