University of Plymouth - Stages 1, 2 and 3 / Mbed OS Task611-mbedos54-solution
Committer:
noutram
Date:
Fri Nov 08 10:31:55 2019 +0000
Revision:
2:06e6936799eb
Parent:
1:d60ed022d866
2019

Who changed what in which revision?

UserRevisionLine numberNew 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 1:d60ed022d866 26 //Thread::wait(2000);
noutram 1:d60ed022d866 27 ThisThread::sleep_for(2000);
noutram 0:9ff439f5bf2e 28 }
noutram 0:9ff439f5bf2e 29 }
noutram 0:9ff439f5bf2e 30
noutram 0:9ff439f5bf2e 31 void Function2()
noutram 0:9ff439f5bf2e 32 {
noutram 0:9ff439f5bf2e 33 while (true) {
noutram 0:9ff439f5bf2e 34 yellowLED = !yellowLED;
noutram 1:d60ed022d866 35 //Thread::wait(1000);
noutram 1:d60ed022d866 36 ThisThread::sleep_for(1000);
noutram 0:9ff439f5bf2e 37 }
noutram 0:9ff439f5bf2e 38 }
noutram 0:9ff439f5bf2e 39
noutram 0:9ff439f5bf2e 40 //Green Flashing
noutram 0:9ff439f5bf2e 41 void Function3()
noutram 0:9ff439f5bf2e 42 {
noutram 0:9ff439f5bf2e 43 while (true) {
noutram 0:9ff439f5bf2e 44 greenLED = !greenLED;
noutram 1:d60ed022d866 45 //Thread::wait(500);
noutram 1:d60ed022d866 46 ThisThread::sleep_for(500);
noutram 0:9ff439f5bf2e 47 }
noutram 0:9ff439f5bf2e 48 }
noutram 0:9ff439f5bf2e 49
noutram 0:9ff439f5bf2e 50
noutram 0:9ff439f5bf2e 51 //Main thread
noutram 0:9ff439f5bf2e 52 int main() {
noutram 0:9ff439f5bf2e 53 redLED = 0;
noutram 0:9ff439f5bf2e 54 yellowLED = 0;
noutram 0:9ff439f5bf2e 55 greenLED = 0;
noutram 0:9ff439f5bf2e 56
noutram 0:9ff439f5bf2e 57 //Create and run threads
noutram 0:9ff439f5bf2e 58 t1.start(Function1);
noutram 0:9ff439f5bf2e 59 t2.start(Function2);
noutram 0:9ff439f5bf2e 60 t3.start(Function3);
noutram 0:9ff439f5bf2e 61
noutram 0:9ff439f5bf2e 62 while(1) {
noutram 0:9ff439f5bf2e 63 //Thread::wait(osWaitForever);
noutram 1:d60ed022d866 64 //Thread::wait(5000);
noutram 1:d60ed022d866 65 ThisThread::sleep_for(5000);
noutram 2:06e6936799eb 66 printf("Awake\n");
noutram 0:9ff439f5bf2e 67 }
noutram 0:9ff439f5bf2e 68 }
noutram 0:9ff439f5bf2e 69