Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 00004 Semaphore sem[] = {(1),(0),(0),(0)}; // Set of semaphores 00005 DigitalOut led[] = {(D13),(D12),(D11),(D10)}; // Set of LEDs 00006 00007 void led_thread(void const* args) { 00008 int i = (int)args-1; // Idx of this task 00009 int inext = (i+1)%4; // Idx of next task 00010 while (true) { 00011 sem[i].wait(); 00012 led[i] = 0; // ith LED on 00013 Thread::wait(500+rand()%500); 00014 led[i] = 1; // ith LED off 00015 sem[inext].release(); // Start new task 00016 } 00017 } 00018 00019 int main (void) { 00020 for(int i=0; i<4; i++) { 00021 led[i]=1; // LEDs off 00022 } 00023 Thread t2(led_thread, (void *)2U); 00024 Thread t3(led_thread, (void *)3U); 00025 Thread t4(led_thread, (void *)4U); 00026 led_thread((void *)1U); 00027 }
Generated on Mon Oct 3 2022 15:18:23 by
1.7.2