Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 9 months ago.
Led blinking multithreading
Hope everyone's well, i have a two thread functions i am calling under "int main()" but one of them works which has the main process while the other one which is "LED_BLINK" does not work i have look up for example on thread and multi-threading for LEDs , how can i let the LED thread work?
1 Answer
6 years, 9 months ago.
Eng,
I would recommend reviewing the Thread guide in our reference documentation. Looking at your code snippet, either your code is incomplete or you just didn't paste the entirety of your program.
Make sure you have code similar to this working:
Thread example
#include "mbed.h" DigitalOut led1(LED1); DigitalOut led2(LED2); Thread thread; void led2_thread() { while (true) { led2 = !led2; wait(1); } } int main() { thread.start(led2_thread); while (true) { led1 = !led1; wait(0.5); } }
This example has an LED that is flashing in the main thread, as well as another thread specifically dedicated to blinking an LED - similar to the desired result you stated in your question.
In addition, once you have that running, you can add the humidity and barometer sensors to the led thread, to the main thread, or even create another thread that is separate from your LED (depending on your specific implementation)
Thank you , i have actually sorted it out using another thread as at the top i have initialized one thread called "thread" i added another thread and called it thread2 , and edit the first thread and called it thread1 so it became like that
thread1.start(Data_Protocol); Thread Reads data from the array
thread2.start(LED_BLINK); Thread for led to be blinking individually
instead of using
thread.start(Data_Protocol); Thread Reads data from the array
thread.start(LED_BLINK); Thread for led to be blinking individually
..... it works well now
posted by 22 Nov 2017
.
posted by Eng Riyadh 20 Nov 2017If you use
Then the message board won't mess up the code formatting.
You need to include all the code if you want people to be able to help. It doesn't look like you've included the two threads.
posted by Andy A 21 Nov 2017