Updated for mbed OS 5.4

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 //Function declarations
00004 void Function1(void const *args);
00005 void Function2(void const *args);
00006 void Function3(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 Thread t3;
00021 
00022 void Function1()
00023 {
00024     while (true) {
00025         redLED = !redLED;
00026         //Thread::wait(2000);
00027         ThisThread::sleep_for(2000);
00028     }
00029 }
00030 
00031 void Function2()
00032 {
00033     while (true) {
00034         yellowLED = !yellowLED;
00035         //Thread::wait(1000);
00036         ThisThread::sleep_for(1000);
00037     }
00038 }
00039 
00040 //Green Flashing
00041 void Function3()
00042 {
00043     while (true) {
00044         greenLED = !greenLED;
00045         //Thread::wait(500);
00046         ThisThread::sleep_for(500);
00047     }
00048 }
00049 
00050 
00051 //Main thread
00052 int main() {
00053     redLED    = 0;
00054     yellowLED = 0;
00055     greenLED  = 0;
00056     
00057     //Create and run threads
00058     t1.start(Function1);           
00059     t2.start(Function2);    
00060     t3.start(Function3);     
00061     
00062     while(1) {
00063         //Thread::wait(osWaitForever);
00064         //Thread::wait(5000);
00065         ThisThread::sleep_for(5000);
00066         printf("Awake\n");  
00067     }
00068 }
00069