I've recently started using Arduino although I have quite a bit of experience of 'C' across the years, C# more recently but C++ not for a while.
I found and tested the often-quoted example about doing several things at the same time and it works OK but I found it rather 'messy' - quite a bit of repeated code structures. So I decided to tidy it, while revising for myself the use of C++.
I have created a 'Task' class which hides (from the user of the class) the continuous monitoring of milliseconds. It doesn't attempt to use a RTOS for task-switching (this has been done elsewhere and works well but has known limitations) - it uses the same methodology as the original 'several things' but in a neater way (I hope!). Code size is only a few more bytes than the original. I haven't actually run it with a servo but checked with serial debug that things are being done at the correct times.
I'd be grateful for any comments. I'm hoping it could be used for any project which needs to run two or more tasks at differing intervals (which appears pretty commonly on this forum, it seems). A zip file is attached.
I appreciate that the original intention was to educate. That's fine if you need to know how to do it at that level. But many posts on the forum are from people who just want to run their tasks and are getting stuck with delay() or similar. They don't need to get involved with manipulating millisecs and several global timers. So I wonder why these people always seem to be referred to 'several things...' when there are easier ways of doing it that they could be pointed to.
If I wanted to make a cake, I would look for a recipe then go and buy some flour. I wouldn't have to learn how to grow the wheat.
You say there 'dozens' of libraries; so I looked and found just one in this site's libraries. So I seem to have done pretty much the same as Metro. Well, at least I've revised my C++ a bit by doing so.
There are more libraries for this than you can shake a stick at.
Yes the purpose of the thread is to teach new people the concept.
I think you missed the point a bit.
You don't need to bake a cake! you just need to buy a ready baked one from a bakery.
Oh, you don't need to learn programmming you just need to buy canned software then complain you don't understand coding.
And yes, it is good to go through the process, I am sure you learned lots, congrats.
I think most have done the exact same thing.