![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
updated for mbed os 5.4
main.cpp@2:22ab4fcc5293, 2019-11-08 (annotated)
- Committer:
- noutram
- Date:
- Fri Nov 08 10:31:30 2019 +0000
- Revision:
- 2:22ab4fcc5293
- Parent:
- 1:cbcb7c2d43cd
2019
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 0:e48f4ddb9393 | 1 | #include "mbed.h" |
noutram | 0:e48f4ddb9393 | 2 | |
noutram | 0:e48f4ddb9393 | 3 | |
noutram | 0:e48f4ddb9393 | 4 | //Function declarations |
noutram | 0:e48f4ddb9393 | 5 | void Function1(); |
noutram | 0:e48f4ddb9393 | 6 | void Function2(); |
noutram | 0:e48f4ddb9393 | 7 | |
noutram | 0:e48f4ddb9393 | 8 | //I/O |
noutram | 0:e48f4ddb9393 | 9 | DigitalOut onBoardLED(LED1); |
noutram | 0:e48f4ddb9393 | 10 | DigitalOut redLED(D7); |
noutram | 0:e48f4ddb9393 | 11 | DigitalOut yellowLED(D6); |
noutram | 0:e48f4ddb9393 | 12 | DigitalOut greenLED(D5); |
noutram | 0:e48f4ddb9393 | 13 | |
noutram | 0:e48f4ddb9393 | 14 | DigitalIn onBoardSwitch(USER_BUTTON); |
noutram | 0:e48f4ddb9393 | 15 | DigitalIn SW1(D4); |
noutram | 0:e48f4ddb9393 | 16 | DigitalIn SW2(D3); |
noutram | 0:e48f4ddb9393 | 17 | |
noutram | 0:e48f4ddb9393 | 18 | Thread t1, t2; |
noutram | 0:e48f4ddb9393 | 19 | |
noutram | 0:e48f4ddb9393 | 20 | void Function1() |
noutram | 0:e48f4ddb9393 | 21 | { |
noutram | 0:e48f4ddb9393 | 22 | while (true) { |
noutram | 0:e48f4ddb9393 | 23 | redLED = !redLED; |
noutram | 1:cbcb7c2d43cd | 24 | ThisThread::sleep_for(2000); |
noutram | 1:cbcb7c2d43cd | 25 | //Thread::wait(2000); //Deprecated |
noutram | 0:e48f4ddb9393 | 26 | } |
noutram | 0:e48f4ddb9393 | 27 | } |
noutram | 0:e48f4ddb9393 | 28 | |
noutram | 0:e48f4ddb9393 | 29 | void Function2() |
noutram | 0:e48f4ddb9393 | 30 | { |
noutram | 0:e48f4ddb9393 | 31 | while (true) { |
noutram | 0:e48f4ddb9393 | 32 | yellowLED = !yellowLED; |
noutram | 1:cbcb7c2d43cd | 33 | ThisThread::sleep_for(1000); |
noutram | 1:cbcb7c2d43cd | 34 | //Thread::wait(1000); //Deprecated |
noutram | 0:e48f4ddb9393 | 35 | } |
noutram | 0:e48f4ddb9393 | 36 | } |
noutram | 0:e48f4ddb9393 | 37 | |
noutram | 0:e48f4ddb9393 | 38 | //Main thread |
noutram | 0:e48f4ddb9393 | 39 | int main() { |
noutram | 0:e48f4ddb9393 | 40 | redLED = 0; |
noutram | 0:e48f4ddb9393 | 41 | yellowLED = 0; |
noutram | 0:e48f4ddb9393 | 42 | |
noutram | 0:e48f4ddb9393 | 43 | //Create and run threads |
noutram | 0:e48f4ddb9393 | 44 | t1.start(Function1); |
noutram | 0:e48f4ddb9393 | 45 | t2.start(Function2); |
noutram | 0:e48f4ddb9393 | 46 | |
noutram | 0:e48f4ddb9393 | 47 | while(1) { |
noutram | 0:e48f4ddb9393 | 48 | //Thread::wait(osWaitForever); |
noutram | 1:cbcb7c2d43cd | 49 | //Thread::wait(5000); //Deprecated |
noutram | 1:cbcb7c2d43cd | 50 | ThisThread::sleep_for(5000); |
noutram | 0:e48f4ddb9393 | 51 | printf("Awake\n"); //Should not happen |
noutram | 0:e48f4ddb9393 | 52 | } |
noutram | 0:e48f4ddb9393 | 53 | } |