Concurrent programs running

I need some help with programming.

I will have a LED which displays Play(LED ON), Pause(LED Blinking), STOP(LED OFF)

Signals are via the serial port.

Firstly, I will be running some eccentric motor by analogwrite(). But it is run via a sequence of about 40 lines.
In the midst of Playing the program, the LED will be ON and the motor will be running.
While I press pause, the program is to hold there and the LED is to start blinking to signal pause
as I press play the program will run back where it was hold and continue from there.

Can I know which function can help me from doing multiple programs yet able to hold the sequence there or what kind of programming I can use to help the main programs seem to run concurrently. Pls advice

Would appreciate if you could show me some code

Try here - the guy looks to have a very similar issue

Had you read this?
http://forum.arduino.cc/index.php?topic=223286.0

Can I know which function can help me from doing multiple programs yet able to hold the sequence there or what kind of programming I can use to help the main programs seem to run concurrently.

There isn't one function. There is a mindset of designing the program so as to not be blocking. On every pass through loop(), check the switches. Then, decide what the next step should be, and if it's time to take that next step. Finite state machines and the blink without delay example are things to look at.

When is Arduino going to add a REFERENCE /TUTORIAL/LEARNING page for FSM ?

Probably about the same time the blink without delay and servo sweep examples get corrected.

From what I see it is a repeated motion of things. Is it possible to run a line of 40 lines of code (main program), yet able to do blinking at the same time?

The main program will be running through the activation of motors and delays (this main program will run like 40 lines of code before ending)

When I sent a signal via serial port, the 40 lines of code will stop in the middle (let's say at the 23rd line of code), like a pause
when another signal is sent, the code will continue from the 23rd line and proceed on.

While this program is running concurrently, the main program is running while, the serial program is waiting for signal.

Is this possible?

I'm sure it is. That sounds like a question that would be best posted under PROGRAMMING, because it sounds like you need programming help more than PROJECT GUIDANCE. You seem to already know which direction your going in.

Thanks

From what I see it is a repeated motion of things. Is it possible to run a line of 40 lines of code (main program), yet able to do blinking at the same time?

The main program will be running through the activation of motors and delays (this main program will run like 40 lines of code before ending)

When I sent a signal via serial port, the 40 lines of code will stop in the middle (let's say at the 23rd line of code), like a pause
when another signal is sent, the code will continue from the 23rd line and proceed on.

While this program is running concurrently, the main program is running while, the serial program is waiting for signal.

Is this possible?

Standard answer #1 applies.

Look at the BlinkWithoutDelay example in the IDE. It uses the principle of checking whether it is time to do something yet, maybe turn an LED on or off, and if not then do something else in the meantime. What you absolutely must not do is to use blocking code such as delay().

@frozen29, I wrote the code in the Thread linked to in Reply #2 to demonstrate how to do the sort of thing you want to do. Its not clear from your previous comments here whether you have read it.

@raschemmel, my demo code is also intended to help fill the gap you have identified - without boring newbies with theory.

...R

frozen29:
When I sent a signal via serial port, the 40 lines of code will stop in the middle (let's say at the 23rd line of code), like a pause when another signal is sent, the code will continue from the 23rd line and proceed on.

OK, let's look at this example. You need to understand what "pause" or "stop" means in the context of a multi-process system. It does not mean that the process loops internally such as in a "while" loop or in the "demonstrator" delay() function though proper versions of such functions including task-switching may be included in a full RTOS.

In the situation you cite, the "pause" is executed by a conditional which examines the necessary signal, and skips to the end of the current process immediately if it is not favourable. Part of this procedure is to set a corresponding switch at the beginning of the process which performs the jump to the current conditional on the next pass.

In some ways this is an "inside-out" form of a process where all the "pauses" actually become the common entry and exit points of the code section and the original entry and exit (if any) points are no more than another "pause" which was effectively a "wait" for the controller to be turned on or reset. You tend to grow into a different mind-set in the program, regarding this not as a slightly inconvenient way to go about things, having to decide where you "left off" last time, but rather as a completely event-driven system where what each process does next, is governed by which event (given an order of priority) has happened. Which is incidentally, germane to how Windows works!

Of course, all processes are implemented in this manner, so that the main "loop" consists of a chain of such processes which proceeds without interruption, slowed only by actual computational elements which are finite in themselves. Even then it may be necessary to split an particularly long process into smaller elements which will be executed sequentially on successive passes through the loop.

The main loop may be a chain of process calls, or simply the process modules themselves, duly contained so that each starts at its beginning and ending to pass onto the following module (and clearly delineated by comment).