Along with structured programming, multitasking provides a very powerful method of programming. Each task is an independent piece of code that can run on itself. In the example below, there are four independent programmes. We can have global variables to share data. Whenever a task goes into a timing phase, the task is switched to the next. If there is no timing phase in a task, YIELDTASK is placed at the beginning of the loop for obvious reasons. It will loop once and switch to the next task. When it receives the focus again, loop once and yield again.

I would like to be able to do the vary same thing with Arduino C with either Arduino IDE or VS Visual Micro.

The Arduino IDE uploads one sketch and the board can remember it, it also saves the sketch before the latest one; you can find the sketches on /sketch with the names sketch.elf and sketch.elf.old

When you say:

Launchtask CheckEmergencyPushButton

Launchtask ControlTankTemp

Launchtask MonitorPushbuttons

Launchtask LCDDisplayUpdate

Are you planning to run different .ino sketches at the same time? If this is the case you will have to upload them in different rounds so you can have all the sketches in one specific folder and then be able to run them at the same time. Is this what you want to do?

If you want to run different parts of code that are located inside the same .ino sketch I suggest you to use pthread, this should allow you to run different tasks at the same time.

Thank you for your reply, CMata_Intel. Judging from your questions I assume you didn't read the links. If you did read the links, especially the first shorth one, you'd understand what I'm up to. Instead or writing a spaghetti string programme, I break it down to small bite size programmes and run then all in one file. It's almost like a sequencer with subroutines. The exception is in a sequencer, you will stay in the routine until the timing function times out. Or you have have to set an elaborate logic scheme to leave the subroutine and return every now and then.

With multitasking, the microprocessor is clocking so fast you get the impression that their running simultaneously. Much like when you have a number of programmes open and running on Windows 10 or Linux. Even a Mac. A takeoff in object programming. They are all self contained. If you need to change one, you don't have to worry about affecting the others. That's one terrific payoff right there.

Look at my example and look at pThread. Very straight forward. Very simple. You can disable one or more tasks by simply placing a comment character in front and the rest will work as happy as can be. By the way, SPLat has a feel like BASIC. By comparison, pThread if very complex to set up.

I was hoping that someone came up with an eloquent approach.

By the way, I know the gentleman who wrote the SPLat language and Multitasking. I'm trying to convince him to work a form of Multitasking out for Arduino C.

Oh, Charlie, I did read the second link. I wasn't very impressed. I guess I'm spoiled. Sorry.

Hello Vincenze. About the example I used.... I simply threw something together. The idea was you take a long speghetti type programme and break it down into its verious components. It's like machine state mapping, with subroutines that can be treated as objects. Polling is like replacing a fuel injector with a carburetor. Interrupts only handle inputs and you are limited. Multitasking can handle anything. How would I use interrupts on LCD display, real time clock monitoring, timing functions, arithmetic computations and so on? Did you read my links?

The trouble, Vicenze, is I read everything there is and the closest I can get to Multitasking is pThreads. They're not eloquent. Have you writen Visual C or Basic? You design the interface and then code the objects. There the module you write code that loops, not event driven. In effect, you have multitasking. That's what I'm after.

Nope, I haven't. pthread is too heavy to deal with. It shouldn't have to be like that. Someone should be able to boil it down to something more manageable. Imagine having to go through similar steps just to print a line of text. By the way, you may be interested in a neat way to programme in finite state machine (FSM). Definition FSM The man who came up with Multitasking and FSM programming is Mr. David Stonier-Gibson. If we had his Multitasking library function and this FSM Tabula for Arduino, we would take Intel/Edison and Arduino into a realm no hobby embedded controller has ever gone. Ideal for university courses and research. Someone should talk to the man. Have any ideas?

Arduino is intended for small, slow and cheap microcontrollers. Typically, they have less than 16kB of RAM.

When you connect an LED to a pin of a microcontroller and change the pin from LOW to HIGH, you want it to be done almost instantaneously. You don't want the microcontroller to wait 2 seconds while another thread reads the RTC and consumes all microcontroller power.

When one microcontroller can't process simultaneous tasks, you just add a second microcontroller that costs $2. The first microcontroller flashes the first LED, the second flashes the second LED.

Then you have the Edison that costs $50, but its Linux natively supports multiprocessing and multitasking. Then you can download a file in one process, read the RTC in the second, update the screen in the third. If you are not satisfied with Linux, install something else, but you'll have problems with drivers.

What can be easier than multiprocessing with fork() in Linux? Using pthreads has its benefits, but it's more complicated.

I used to represent SPLat in USA and Canada. I'm retired and decided to play with Intel/Edison with the Arduino board and I programme the lot with Visual Studio 2015/Micro. It's lots of fun. But, I wish I could multitask as I can with EC1. I can also do this on their more sophisticated HMI430. But the thought that I can do this on EC1 without event lag as you identified above is amazing and a natural for simplified FSM programming.

About my silly programme: As one element of the programme waits for someone to push a button, it is running the flashing element and monitoring the water temperature control element all at the same time. And you don't notice a delay. The controller clocks so fast through the machine codes you simply don't notice it.As soon as you hit that push-button, Bingo. If I decide to skip with the Flash_The_Light element, I simply place a comment (; semi-colon) in front of Luanchtask Flash_The_Light. You can launch a task from within a task and kill it as well. You will note that the language is very much like BASIC but a bit more complex. You don't have libraries to include. I'm not trying to push the language, but I do wish to demonstrate how simple multitasking can be employed on a dirt cheap controller like EC1.

Vincenze, I understand where you're coming from but I'm asking you to think outside of the box. With the computing power available on the Intel/Edison processor, surely, we can come up with something akin to Multitask. Or is a small Australian company more savvy than Intel? And I've been told that certain Arduino micro-controllers can handle it. And whilst we're at it... wouldn't it be nice to have a version of SimpleHMI to use an Android phones for HMI applications via Bluetooth? SPLat Controls - SimpleHMI - Free Android HMI app

My_Silly_Programme: ;This is an actual programme. It can be downloaded into a SPLat controller with their IDE. 27 lines of code including Multitasking.

Launchtask Pushbutton

Launchtask Flash_The_Light

Launchtask Keep_Water_Warm

RunTasksForever

WaitPushButton = 1 ; input

PushbuttonLight = 6 ;output

FlashingLight = 7 ;output

WaterThermoSwitch = 2 ;input

WaterHeater = 8 ;output

Pushbutton: ;This programme element will wait for someone to hit that button.