David Huertas / Mbed 2 deprecated lab3

Dependencies:   mbed mbed-rtos

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 DigitalOut led1(LED6);
00004 DigitalOut led2(LED1);
00005 
00006 Mutex mutex;
00007  
00008 uint32_t cont =0;
00009 bool done[2] = {0,0};
00010 
00011 Thread t1;
00012 Thread t2;
00013 
00014 void thread1( const int *i){
00015     int conth;
00016     int conth2 =0;
00017     while(conth2<100){
00018         mutex.lock();
00019         conth = cont;
00020         conth2++;
00021         conth++;
00022         Thread::wait(10);
00023         cont = conth;
00024         printf("  %d\n\r ",cont);
00025         mutex.unlock();
00026         }
00027     done[(int)i] =1;
00028     }
00029 
00030     
00031 int main(){
00032     t1.start(callback(thread1,  (int*) 1));
00033     t2.start(callback(thread1,  (int*) 2));
00034     while(1){
00035         Thread::wait(1);
00036         if(done[0] && done[1]){
00037             if(cont == 200){
00038                 led1=1;
00039                 }
00040             else{
00041                 led2 = 1;
00042                 }
00043             }
00044         }
00045     }
00046