2019
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 //updated for 2019 00004 00005 //Function declarations 00006 void Function1(); 00007 void Function2(); 00008 00009 //I/O 00010 DigitalOut onBoardLED(LED1); 00011 DigitalOut redLED(PE_15); 00012 DigitalOut yellowLED(PB_10); 00013 DigitalOut greenLED(PB_11); 00014 00015 DigitalIn onBoardSwitch(USER_BUTTON); 00016 DigitalIn SW1(PE_12); 00017 DigitalIn SW2(PE_14); 00018 00019 //Create thread objects 00020 Thread t1, t2, t3; 00021 00022 //Thread 00023 void Function1() 00024 { 00025 while (true) { 00026 redLED = !redLED; 00027 ThisThread::sleep_for(2000); 00028 } 00029 } 00030 00031 //Thread 00032 void Function2() 00033 { 00034 while (true) { 00035 yellowLED = !yellowLED; 00036 ThisThread::sleep_for(1000); 00037 } 00038 } 00039 00040 //Green Flashing 00041 void Function3() 00042 { 00043 while (true) { 00044 greenLED = !greenLED; 00045 ThisThread::sleep_for(500); 00046 } 00047 } 00048 00049 //Main thread 00050 int main() { 00051 //Initial state 00052 redLED = 0; 00053 yellowLED = 0; 00054 greenLED = 0; 00055 00056 //Create and run threads (C function pointers) 00057 t1.start(Function1); 00058 t2.start(Function2); 00059 t3.start(Function3); 00060 00061 //Main thread loop 00062 while(1) { 00063 //ThisThread::sleep_for(osWaitForever); 00064 ThisThread::sleep_for(5000); 00065 printf("Main is Awake\n"); //Should not happen when osWaitForever is used 00066 } 00067 }
Generated on Thu Jul 21 2022 10:38:40 by
1.7.2