Go Down

Topic: More complex, complete examples that do several things at once (Read 1 time) previous topic - next topic


Yes your paradigm of having to do many things at once is just a personal mental roadblock. An arduino can execute instructions very fast and can make it seem as if it is doing many things at once even though it's just doing one thing at a time.

So you have a list of independent tasks that have to be performed. You just have the main loop() function work it's way done that list, each task could be just a user written function that knows how to accomplish that one task. The only requirement is that any one task is not allowed to just stop and wait or loop testing for something before doing something. If it's not time for that task to do something it just returns control back to the main loop and next time the task is called from the main loop it checks if it's now time to do something or not. The arduino functions millis() gives you a free running counter that value you can use to measure passing time intervals.




Thanks a lot for the responses, very helpful.

I really would love to see a more complete example of a real use-case doing LCD (or some other form of) UI, serial and some other things at once. In principle I know how it should be done, but like with the simpler examples, seeing how others do it (and do it well, unlike my own first exeriments) would help me, I think.

Are there no examples of larger projects with complete sourcecode to be examined by newbies?

It is also interesting to me how people organize code, what conventions they invent, etc.

Also it would interest me, how much people fit into their Arduinos


Using interrupts would be a simple way to achieve that.


My advice here (the programming, not cooking bacon) is to chart the program first. There are a number of ways to chart programs including the simple flowchart (which I learnt when learning Fortran) and the structure chart (which I learnt when learning Cobol).

Many many coding problems stem from us diving into the code without having thought through what it is we're trying to do, and how. And the more complex it is, the more fraught with danger it is....

Then once it's charted, maybe even flesh it out further on paper in pseudo-code. Pseudo code lets you write down the logic of the program without getting tied up in the nuances of the syntax.

And make a "coding to-do list" by mapping out the sketch (to use Arduino-speak) by typing in a heap of comments showing the structure of the code and that will remind you to code each part and not forget stuff.

I ALWAYS* do it that way....


* just kidding
Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Go Up