From c65a316c964f3a40536ff3826c4a034e4516dbc1 Mon Sep 17 00:00:00 2001 From: Lorenzo Maiorfi Date: Sat, 14 Oct 2017 08:51:08 +0200 Subject: [PATCH] Thread separato --- main.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index fb0734f..ff671ad 100644 --- a/main.cpp +++ b/main.cpp @@ -9,20 +9,27 @@ static DigitalOut led2(LED2); static DigitalOut led3(LED6); static DigitalOut led4(LED5); -int main() -{ - s_leds.push_back(led1); - s_leds.push_back(led2); - s_leds.push_back(led3); - s_leds.push_back(led4); +static Thread s_thread_blink; +void thread_proc_blink(std::vector *pleds) +{ while (true) { - for (std::vector::iterator it=s_leds.begin();it!=s_leds.end();it++) + for (std::vector::iterator it = pleds->begin(); it != pleds->end(); it++) { it->write(!it->read()); wait_ms(125); } } +} + +int main() +{ + s_leds.push_back(led1); + s_leds.push_back(led2); + s_leds.push_back(led3); + s_leds.push_back(led4); + + s_thread_blink.start(callback(thread_proc_blink, &s_leds)); } \ No newline at end of file