Skip to content
Permalink
9fed8157b1
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
57 lines (46 sloc) 1.01 KB
#include <mbed.h>
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
// Interrupt Handler
InterruptIn theButton(BUTTON1);
//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(5000);
// Set a Signal to blink LED3
thread2.flags_set(0x42);
}
}
void led3_thread() {
//Loop forever.
while (1){
//With for the Signal before continuing
ThisThread::flags_wait_any(0x42);
for (int x=0; x<5; x++) {
led3 = !led3;
thread_sleep_for(100);
}
}
}
void buttonHandler(){
// Button handler interrupt, also sets flags.
thread2.flags_set(0x42);
}
//Main Program
int main() {
//Bind the interupt to a function
theButton.rise(&buttonHandler);
//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);
}
}