2019

Committer:
noutram
Date:
Fri Sep 20 15:14:06 2019 +0000
Revision:
5:5f579d4074a0
Parent:
3:40d2f4b36756
2019

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:e48f4ddb9393 1 #include "mbed.h"
noutram 0:e48f4ddb9393 2
noutram 5:5f579d4074a0 3 //updated for 2019
noutram 0:e48f4ddb9393 4
noutram 0:e48f4ddb9393 5 //Function declarations
noutram 0:e48f4ddb9393 6 void Function1();
noutram 0:e48f4ddb9393 7 void Function2();
noutram 0:e48f4ddb9393 8
noutram 0:e48f4ddb9393 9 //I/O
noutram 0:e48f4ddb9393 10 DigitalOut onBoardLED(LED1);
noutram 1:20f8dc1354d0 11 DigitalOut redLED(PE_15);
noutram 1:20f8dc1354d0 12 DigitalOut yellowLED(PB_10);
noutram 1:20f8dc1354d0 13 DigitalOut greenLED(PB_11);
noutram 0:e48f4ddb9393 14
noutram 0:e48f4ddb9393 15 DigitalIn onBoardSwitch(USER_BUTTON);
noutram 1:20f8dc1354d0 16 DigitalIn SW1(PE_12);
noutram 1:20f8dc1354d0 17 DigitalIn SW2(PE_14);
noutram 0:e48f4ddb9393 18
noutram 1:20f8dc1354d0 19 //Create thread objects
noutram 3:40d2f4b36756 20 Thread t1, t2, t3;
noutram 0:e48f4ddb9393 21
noutram 1:20f8dc1354d0 22 //Thread
noutram 0:e48f4ddb9393 23 void Function1()
noutram 0:e48f4ddb9393 24 {
noutram 0:e48f4ddb9393 25 while (true) {
noutram 0:e48f4ddb9393 26 redLED = !redLED;
noutram 3:40d2f4b36756 27 ThisThread::sleep_for(2000);
noutram 0:e48f4ddb9393 28 }
noutram 0:e48f4ddb9393 29 }
noutram 0:e48f4ddb9393 30
noutram 1:20f8dc1354d0 31 //Thread
noutram 0:e48f4ddb9393 32 void Function2()
noutram 0:e48f4ddb9393 33 {
noutram 0:e48f4ddb9393 34 while (true) {
noutram 0:e48f4ddb9393 35 yellowLED = !yellowLED;
noutram 3:40d2f4b36756 36 ThisThread::sleep_for(1000);
noutram 3:40d2f4b36756 37 }
noutram 3:40d2f4b36756 38 }
noutram 3:40d2f4b36756 39
noutram 3:40d2f4b36756 40 //Green Flashing
noutram 3:40d2f4b36756 41 void Function3()
noutram 3:40d2f4b36756 42 {
noutram 3:40d2f4b36756 43 while (true) {
noutram 3:40d2f4b36756 44 greenLED = !greenLED;
noutram 3:40d2f4b36756 45 ThisThread::sleep_for(500);
noutram 0:e48f4ddb9393 46 }
noutram 0:e48f4ddb9393 47 }
noutram 0:e48f4ddb9393 48
noutram 0:e48f4ddb9393 49 //Main thread
noutram 0:e48f4ddb9393 50 int main() {
noutram 1:20f8dc1354d0 51 //Initial state
noutram 0:e48f4ddb9393 52 redLED = 0;
noutram 0:e48f4ddb9393 53 yellowLED = 0;
noutram 1:20f8dc1354d0 54 greenLED = 0;
noutram 0:e48f4ddb9393 55
noutram 1:20f8dc1354d0 56 //Create and run threads (C function pointers)
noutram 0:e48f4ddb9393 57 t1.start(Function1);
noutram 0:e48f4ddb9393 58 t2.start(Function2);
noutram 3:40d2f4b36756 59 t3.start(Function3);
noutram 3:40d2f4b36756 60
noutram 1:20f8dc1354d0 61 //Main thread loop
noutram 0:e48f4ddb9393 62 while(1) {
noutram 3:40d2f4b36756 63 //ThisThread::sleep_for(osWaitForever);
noutram 3:40d2f4b36756 64 ThisThread::sleep_for(5000);
noutram 1:20f8dc1354d0 65 printf("Main is Awake\n"); //Should not happen when osWaitForever is used
noutram 0:e48f4ddb9393 66 }
noutram 0:e48f4ddb9393 67 }