Stage-1 Students SoCEM / Mbed 2 deprecated Task611

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 
00004 //Function declarations
00005 void Function1(void const *args);
00006 void Function2(void const *args);
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;
00019 Thread* t2;
00020 
00021 void Function1(void const *args)
00022 {
00023     while (true) {
00024         redLED = !redLED;
00025         Thread::wait(2000);
00026     }
00027 }
00028 
00029 void Function2(void const *args)
00030 {
00031     while (true) {
00032         yellowLED = !yellowLED;
00033         Thread::wait(1000);
00034     }
00035 }
00036 
00037 //Main thread
00038 int main() {
00039     redLED    = 0;
00040     yellowLED = 0;
00041     
00042     //Create and run threads
00043     t1 = new Thread(Function1);           
00044     t2 = new Thread(Function2);    
00045     
00046     while(1) {
00047         //Thread::wait(osWaitForever);
00048         Thread::wait(5000);
00049         printf("Awake\n");  //Should not happen
00050     }
00051 }