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.
9 years, 9 months ago.
How to run 2 tasks simultaniously
me and a friend started a project in wich we need to run a working clock,
herefore we made a code but we need the code to run 2 tasks not 1
we have 1 task wich let the led display a number every 10 seconds and need another one that changes the number every 1 second
10 - 11 - 12 - 13 - 14 - 15 -16 - 17 - 18 - 19 - 20 -21
we don't know what code to use. please help
Thank you :)
1 Answer
9 years, 9 months ago.
Two options:
Simple way: Use a Ticker running at 1 second for the 1 second task Use a Ticker running at 10 seconds for the 10 second task.
Or if you want them to be perfectly in sync run a single ticker at 1 second and count how many times it runs, every 10 times run the 10 second code. (use the static keyword so that the counter variable keeps its value between calls).
Harder but more flexible way: Use the mbed RTOS and run multiple threads, one for each task you want to run. Let the operating system work out how to switch between them.
Also if you want helpful answers in the future please refrain from filling the questions board with junk like your other two posts.