Running multiple waiting functions simultanously

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?

What's my motivation?
(My solution involves filling the silences with activity)

State Machine

Arduino Multiple Things

Several Things at a Time

1 Like

find a solution to the problem! Programming will never be the same if you have a solution...

"If you're not part of the solution, you're part of the precipitate"

4 Likes

Either You rewrite the code to work without delay or You run a real time operating system with preemptive scheduling. The latter calls for a controller having more power than the Arduinos.

If you find the solution, we will be able to design a function that makes cakes, and write it this way:
1-"-turn- the- oven- on-350-degrees" (the function does the job of regulating the oven temperature
2--"prepare-the-pastry" (the function prepares the pastry! involves waiting situations)
3-- "prepare-the-icing" ( this function also has waiting times. It executes simultanously with the prepare-the-pastry.
4-"wait-for-pastry-dont && oven-hot". (prepare-icing could be running, if not finished)
5- "put-the-prepared-pastry-in-oven"
6- wait-25-minutes (or until cooked) (if not already finished, the prepare-icing is still running)
7-" put-the-cak-out-of-oven"
8- "wait 15 minutes or until cake cold"
9- "wait-for-icing-done" (icing preparation was running since step 3.
10 -"put-the-icing-on-cake"
11 "Cake-Done!"

this is the way we could program if you find a solution!

Sorry, in the example above, I forgot to turn the oven off!

If you're looking for a simple way to express concurrency, I can recommend the occam language.

1 Like

Of course, such a problem cannot use the simplistic delay() function. I conclude that you do not have a solution without a RTOS. There is a solution, believe me.

We need to execute this simple problem on Arduino, with the basic tools of the language. Running 2 functions simultanously shoud be simple, don't you think so?

I believe you. I've done it hundreds of times in my career. I also believe you are trying to get someone else to do your homework for you. I listed the tutorials you need to formulate a solution in post #3. No one is going to do it for you. I'm out...

2 Likes

It absolutely is simple - on a processor with two cores. Or on two processors.
Otherwise, you have to make it look like the two functions are running simultaneously.

I do not want anyone do the job for me: it is already done! I have a solution.

Whoop-de-do!

You posted in "guidance" when you should have posted in the showcase.

Use the flag icon below to attract the attention of a moderator, and ask them to move it for you.

Please post your solution.

By the way, in my cake-making example, there could be some hanging situations, where the application is waiting for events that never happen. (waitinf for a hot oven, for example: the heating element is burned.) We can avoid these hanging situation by adding a timer where we wait for an event. If the event does not happen within the specified time, the application reacts accordingly, without hanging forever. Time passing is an absolute certitude.

Reading Your post #7 this would be a simple task done by any Arduino.
Use the state machine technic.

What needs absolut simultaneous execution in the project? Things done a few microseconds apart solves almost every practical situation.

And it runs on Arduino.

Congratulations - you've invented cooperative multitasking.

1 Like