Task 6.1.1

Dependencies:   mbed-rtos mbed

Committer:
noutram
Date:
Tue Mar 08 11:47:37 2016 +0000
Revision:
0:c19d469c49a2
Task 6.1.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:c19d469c49a2 1 #include "mbed.h"
noutram 0:c19d469c49a2 2 #include "rtos.h"
noutram 0:c19d469c49a2 3
noutram 0:c19d469c49a2 4 //Function declarations
noutram 0:c19d469c49a2 5 void Function1(void const *args);
noutram 0:c19d469c49a2 6 void Function2(void const *args);
noutram 0:c19d469c49a2 7
noutram 0:c19d469c49a2 8 //I/O
noutram 0:c19d469c49a2 9 DigitalOut onBoardLED(LED1);
noutram 0:c19d469c49a2 10 DigitalOut redLED(D7);
noutram 0:c19d469c49a2 11 DigitalOut yellowLED(D6);
noutram 0:c19d469c49a2 12 DigitalOut greenLED(D5);
noutram 0:c19d469c49a2 13
noutram 0:c19d469c49a2 14 DigitalIn onBoardSwitch(USER_BUTTON);
noutram 0:c19d469c49a2 15 DigitalIn SW1(D4);
noutram 0:c19d469c49a2 16 DigitalIn SW2(D3);
noutram 0:c19d469c49a2 17
noutram 0:c19d469c49a2 18 Thread* t1;
noutram 0:c19d469c49a2 19 Thread* t2;
noutram 0:c19d469c49a2 20
noutram 0:c19d469c49a2 21 void Function1(void const *args)
noutram 0:c19d469c49a2 22 {
noutram 0:c19d469c49a2 23 while (true) {
noutram 0:c19d469c49a2 24 redLED = !redLED;
noutram 0:c19d469c49a2 25 Thread::wait(2000);
noutram 0:c19d469c49a2 26 }
noutram 0:c19d469c49a2 27 }
noutram 0:c19d469c49a2 28
noutram 0:c19d469c49a2 29 void Function2(void const *args)
noutram 0:c19d469c49a2 30 {
noutram 0:c19d469c49a2 31 while (true) {
noutram 0:c19d469c49a2 32 yellowLED = !yellowLED;
noutram 0:c19d469c49a2 33 Thread::wait(1000);
noutram 0:c19d469c49a2 34 }
noutram 0:c19d469c49a2 35 }
noutram 0:c19d469c49a2 36
noutram 0:c19d469c49a2 37 //Main thread
noutram 0:c19d469c49a2 38 int main() {
noutram 0:c19d469c49a2 39 redLED = 0;
noutram 0:c19d469c49a2 40 yellowLED = 0;
noutram 0:c19d469c49a2 41
noutram 0:c19d469c49a2 42 //Create and run threads
noutram 0:c19d469c49a2 43 t1 = new Thread(Function1);
noutram 0:c19d469c49a2 44 t2 = new Thread(Function2);
noutram 0:c19d469c49a2 45
noutram 0:c19d469c49a2 46 while(1) {
noutram 0:c19d469c49a2 47 //Thread::wait(osWaitForever);
noutram 0:c19d469c49a2 48 Thread::wait(5000);
noutram 0:c19d469c49a2 49 printf("Awake\n"); //Should not happen
noutram 0:c19d469c49a2 50 }
noutram 0:c19d469c49a2 51 }