Skip to content
Permalink
21bc4128eb
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
44 lines (36 sloc) 726 Bytes
#include <mbed.h>
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
//Create an empty thread object ready to attach a function
Thread thread;
Thread thread2;
//Function to deal with blinking the second LED
void led2_thread() {
//Loop forever
while (true) {
led2 = !led2;
thread_sleep_for(1000);
thread2.signal_set(0x42);
}
}
void led3_thread() {
//Loop forever
while (1){
thread2.signal_wait(0x42);
for (int x=0; x<5; x++) {
led3 = !led3;
thread_sleep_for(100);
}
}
}
//Main Program
int main() {
//Attach the function to the Thread then Start it
thread.start(led2_thread);
thread2.start(led3_thread);
while (true) {
led1 = !led1;
thread_sleep_for(500);
}
}