updated for mbed os 5.4
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 00004 //Function declarations 00005 void Function1(); 00006 void Function2(); 00007 00008 //I/O 00009 DigitalOut onBoardLED(LED1); 00010 DigitalOut redLED(D7); 00011 DigitalOut yellowLED(D6); 00012 DigitalOut greenLED(D5); 00013 00014 DigitalIn onBoardSwitch(USER_BUTTON); 00015 DigitalIn SW1(D4); 00016 DigitalIn SW2(D3); 00017 00018 Thread t1, t2; 00019 00020 void Function1() 00021 { 00022 while (true) { 00023 redLED = !redLED; 00024 ThisThread::sleep_for(2000); 00025 //Thread::wait(2000); //Deprecated 00026 } 00027 } 00028 00029 void Function2() 00030 { 00031 while (true) { 00032 yellowLED = !yellowLED; 00033 ThisThread::sleep_for(1000); 00034 //Thread::wait(1000); //Deprecated 00035 } 00036 } 00037 00038 //Main thread 00039 int main() { 00040 redLED = 0; 00041 yellowLED = 0; 00042 00043 //Create and run threads 00044 t1.start(Function1); 00045 t2.start(Function2); 00046 00047 while(1) { 00048 //Thread::wait(osWaitForever); 00049 //Thread::wait(5000); //Deprecated 00050 ThisThread::sleep_for(5000); 00051 printf("Awake\n"); //Should not happen 00052 } 00053 }
Generated on Thu Jul 14 2022 01:56:53 by
1.7.2