Permalink
Cannot retrieve contributors at this time
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?
7148_Labs_2223/Future/Session4_ThreadSignals/src/main.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (36 sloc)
726 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} |