Nicholas Outram
/
Task611-mbedos54-solution
Updated for mbed OS 5.4
Fork of Task611-mbedos54-solution by
main.cpp@0:9ff439f5bf2e, 2017-03-30 (annotated)
- Committer:
- noutram
- Date:
- Thu Mar 30 13:35:55 2017 +0000
- Revision:
- 0:9ff439f5bf2e
updated for mbed os 5.4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 0:9ff439f5bf2e | 1 | #include "mbed.h" |
noutram | 0:9ff439f5bf2e | 2 | |
noutram | 0:9ff439f5bf2e | 3 | //Function declarations |
noutram | 0:9ff439f5bf2e | 4 | void Function1(void const *args); |
noutram | 0:9ff439f5bf2e | 5 | void Function2(void const *args); |
noutram | 0:9ff439f5bf2e | 6 | void Function3(void const *args); |
noutram | 0:9ff439f5bf2e | 7 | |
noutram | 0:9ff439f5bf2e | 8 | //I/O |
noutram | 0:9ff439f5bf2e | 9 | DigitalOut onBoardLED(LED1); |
noutram | 0:9ff439f5bf2e | 10 | DigitalOut redLED(D7); |
noutram | 0:9ff439f5bf2e | 11 | DigitalOut yellowLED(D6); |
noutram | 0:9ff439f5bf2e | 12 | DigitalOut greenLED(D5); |
noutram | 0:9ff439f5bf2e | 13 | |
noutram | 0:9ff439f5bf2e | 14 | DigitalIn onBoardSwitch(USER_BUTTON); |
noutram | 0:9ff439f5bf2e | 15 | DigitalIn SW1(D4); |
noutram | 0:9ff439f5bf2e | 16 | DigitalIn SW2(D3); |
noutram | 0:9ff439f5bf2e | 17 | |
noutram | 0:9ff439f5bf2e | 18 | Thread t1; |
noutram | 0:9ff439f5bf2e | 19 | Thread t2; |
noutram | 0:9ff439f5bf2e | 20 | Thread t3; |
noutram | 0:9ff439f5bf2e | 21 | |
noutram | 0:9ff439f5bf2e | 22 | void Function1() |
noutram | 0:9ff439f5bf2e | 23 | { |
noutram | 0:9ff439f5bf2e | 24 | while (true) { |
noutram | 0:9ff439f5bf2e | 25 | redLED = !redLED; |
noutram | 0:9ff439f5bf2e | 26 | Thread::wait(2000); |
noutram | 0:9ff439f5bf2e | 27 | } |
noutram | 0:9ff439f5bf2e | 28 | } |
noutram | 0:9ff439f5bf2e | 29 | |
noutram | 0:9ff439f5bf2e | 30 | void Function2() |
noutram | 0:9ff439f5bf2e | 31 | { |
noutram | 0:9ff439f5bf2e | 32 | while (true) { |
noutram | 0:9ff439f5bf2e | 33 | yellowLED = !yellowLED; |
noutram | 0:9ff439f5bf2e | 34 | Thread::wait(1000); |
noutram | 0:9ff439f5bf2e | 35 | } |
noutram | 0:9ff439f5bf2e | 36 | } |
noutram | 0:9ff439f5bf2e | 37 | |
noutram | 0:9ff439f5bf2e | 38 | //Green Flashing |
noutram | 0:9ff439f5bf2e | 39 | void Function3() |
noutram | 0:9ff439f5bf2e | 40 | { |
noutram | 0:9ff439f5bf2e | 41 | while (true) { |
noutram | 0:9ff439f5bf2e | 42 | greenLED = !greenLED; |
noutram | 0:9ff439f5bf2e | 43 | Thread::wait(500); |
noutram | 0:9ff439f5bf2e | 44 | } |
noutram | 0:9ff439f5bf2e | 45 | } |
noutram | 0:9ff439f5bf2e | 46 | |
noutram | 0:9ff439f5bf2e | 47 | |
noutram | 0:9ff439f5bf2e | 48 | //Main thread |
noutram | 0:9ff439f5bf2e | 49 | int main() { |
noutram | 0:9ff439f5bf2e | 50 | redLED = 0; |
noutram | 0:9ff439f5bf2e | 51 | yellowLED = 0; |
noutram | 0:9ff439f5bf2e | 52 | greenLED = 0; |
noutram | 0:9ff439f5bf2e | 53 | |
noutram | 0:9ff439f5bf2e | 54 | //Create and run threads |
noutram | 0:9ff439f5bf2e | 55 | t1.start(Function1); |
noutram | 0:9ff439f5bf2e | 56 | t2.start(Function2); |
noutram | 0:9ff439f5bf2e | 57 | t3.start(Function3); |
noutram | 0:9ff439f5bf2e | 58 | |
noutram | 0:9ff439f5bf2e | 59 | while(1) { |
noutram | 0:9ff439f5bf2e | 60 | //Thread::wait(osWaitForever); |
noutram | 0:9ff439f5bf2e | 61 | Thread::wait(5000); |
noutram | 0:9ff439f5bf2e | 62 | printf("Awake\n"); //Should not happen |
noutram | 0:9ff439f5bf2e | 63 | } |
noutram | 0:9ff439f5bf2e | 64 | } |
noutram | 0:9ff439f5bf2e | 65 |