Blink using threads

Committer:
lmottola
Date:
Thu Nov 08 12:37:42 2018 +0000
Revision:
0:f6371c0a2f6f
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lmottola 0:f6371c0a2f6f 1 #include "mbed.h"
lmottola 0:f6371c0a2f6f 2
lmottola 0:f6371c0a2f6f 3 DigitalOut led1(LED1);
lmottola 0:f6371c0a2f6f 4 DigitalOut led2(LED2);
lmottola 0:f6371c0a2f6f 5 Thread thread;
lmottola 0:f6371c0a2f6f 6
lmottola 0:f6371c0a2f6f 7 void led2_thread() {
lmottola 0:f6371c0a2f6f 8 while (true) {
lmottola 0:f6371c0a2f6f 9 led2 = !led2;
lmottola 0:f6371c0a2f6f 10 wait(1);
lmottola 0:f6371c0a2f6f 11 }
lmottola 0:f6371c0a2f6f 12 }
lmottola 0:f6371c0a2f6f 13
lmottola 0:f6371c0a2f6f 14 int main() {
lmottola 0:f6371c0a2f6f 15 // Create a thread to execute the function led2_thread
lmottola 0:f6371c0a2f6f 16 thread.start(led2_thread);
lmottola 0:f6371c0a2f6f 17 // Now led2_thread is executing concurrently with main at this point
lmottola 0:f6371c0a2f6f 18
lmottola 0:f6371c0a2f6f 19 while (true) {
lmottola 0:f6371c0a2f6f 20 led1 = !led1;
lmottola 0:f6371c0a2f6f 21 wait(0.5);
lmottola 0:f6371c0a2f6f 22 }
lmottola 0:f6371c0a2f6f 23 }