CAN YOU SOLVE THIS CHALLENGE?
I have been trying for a while to run SIMULTANOUSLY two or more functions, each function having multiple internal "waiting conditions". The waiting conditions are not important: they could be waiting for an external input, an internal event, etc. Since the most common waiting condition is time, I would like to write two functions that both wait for time internally, and make them run simultanously. For example:
Say the first function sends an arbitrary string in morse. I chose this function because it has a lot of waiting conditions in it. The morse sender is quite simple: read a character in the string to send, find the corresponding morse code, then serially output well timed bips and silence. (Sending a bip is simply setting an output HIGH, and sending a silence, is setting this same output LOW .)
A dot could be a 100mSec bip followed by a 100mSec silence, a dash could be a 300mSec bip followed by a 100mSec silence, a space between characters could be a 400mSec silence. The morse sender works only if he has a string to send, otherwise he does nothing.
In fact, writing the morse sender function is a simple job. BUT..
We also want to run simultanously any another "waiting" function, while the morse sender above is sending his string. This second function could be whatever you want, as long as it also have many internal waiting conditions. Since we already have written the code for a morse sender, the second function we want running simultanously could simply be a second morse sender!
The second morse sender will have different timings (Ex: his dot is 111 mSec, his dash is 333 mSec, etc.) and he sends his own arbitrary string on demand.( Of course, the two morse sender will have their own output pin.) Remember: We want our two morse senders send their respective message simultanously.
One more restriction: because of the high burden imposed by a multi tasking environment, we do not want to use a multi tasker: our morse senders must be designed simply using the basic language tools. (if, while, do, etc...) Solving this problem would open up infinite programming possibilities. I am still working on the problem, and hope I will have something to propose soon.
What is your solution?