How to call multiples functions within the loop{ } and have them execute in parallel

Loop {

......
..........
.......
if condition {
function(1) ;
function2()
function(3)
}

}

See Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE

Your post was MOVED to its current location as it is more suitable.

You can't have them execute in parallel. Arduino boards mostly have only one CPU core and no operating system to allow multiple threads or processes to share the same core.

But you can make it appear that the functions are operating in parallel to a human. To do that, you have to write your functions in a way that they perform their tasks as many small steps, and each time the function is called, it only executes one step, so that it lasts only a fraction of a second. This way, each of your functions is performing one small step each time loop() executes, and it appears to a human like all functions are running in parallel.

How to write your functions like that depends on what the function is doing. If you can tell us more, we can suggest ways to achieve it.

void
loop (void)
{
    ...
    if (condition) {
        function1 ();
        function2 ();
        function3 ();
    }
    ...
}

yes, that works

But they are executed one after the other, not in parallel.
As @PaulRB wrote, we need to know more about the functionality to give an advice.

i'm not making the assumption that he needs a multi-processor code or an FPGA.

this is an Arduino Forum

But he asked 'and have them execute in parallel'.
So the answer must be:
No that doesn't work.

Written correctly the functions may be made to appear to work in parallel which may be good enough, but we are short on details from @helloworld21

do you really think he knows what that means if he's looking for help on this forum?

on another thread, a gal described a function as a "segment"

Hey! I resemble that remark.

there's also the perception of simultaneous -- within a second of one another, msec, usec, nsec.

i heard a story about real-time requirements that end with a guy describing a data collector that disintegrates within of few msec of the event being monitored next to a nuclear weapon

looking forward to hearing from the OP

Thanks a lot all of you. i appreciate you taking valuable time to answers my questions..

Basically
I wanted to the following :
{
ringBell() ; // with or whiteout short interruptions
openUP_Gates() ;
Flash_LEDs() ;
}
all happening at the same time.

See Several things at the same time

consider


const byte pinLed  = 13;
const byte pinBell = 12;
const byte pinGate = 11;

byte pinsOut [] = { pinLed, pinBell, pinGate };
byte pinBut = A1;

unsigned long msec;
unsigned long msecLedLst;
unsigned long msecBellLst;

const unsigned long LedPeriod     = 250;
const unsigned long BellOnPeriod  = 100;
const unsigned long BellOffPeriod = 1000 - BellOnPeriod;

byte  run = false;

enum { Off = HIGH, On = LOW };

// -----------------------------------------------------------------------------
int
butPressed ()
{
    static byte butState = Off;
           byte but      = digitalRead (pinBut);

    // check for change 
    if (butState != but)  {
        butState = but;
        delay (10);     // debounce

        if (On == but)  // check if just pressed
            return 1;
    }
    return 0;
}

// -----------------------------------------------------------------------------
void
loop (void)
{
    msec = millis ();
    
    // check for button pressed
    if (butPressed ())  {
        if (run)        // if on turn off, if off turn on
            digitalWrite (pinGate, Off);
        else
            digitalWrite (pinGate, On);

        run = ! run;    // toggle
    }

    if (run)  {
        // flash LED
        if (msec > msecLedLst)  {
            msecLedLst = msec + LedPeriod;
            digitalWrite (pinLed, ! digitalRead (pinLed));      // toggle
        }

        // bang bell once / sec
        if (msec > msecBellLst)  {
            byte bell = digitalRead (pinBell);
            if (On == bell)
                msecBellLst = msec + BellOffPeriod;
            else
                msecBellLst = msec + BellOnPeriod;

            digitalWrite (pinBell, ! bell);
        }
    }
}

// -----------------------------------------------------------------------------
void
setup (void)
{
    Serial.begin (9600);

    pinMode (pinBut, INPUT_PULLUP);

    for (unsigned n = 0; n < sizeof(pinsOut); n++)  {
        digitalWrite (pinsOut [n], Off);
        pinMode      (pinsOut [n], OUTPUT);
    }
}

thanks a lot, i will study your proposition

Hi gcjr ;
msecLedLst and msecBellLst where never initialized when you enter the loop() { }.
how can we do test on them ?

Hi welcome.

I guess my first question is; what is your goal?

While we don't know what board you are using, most likely it has one CPU core. Which means it can only do one thing at a time. If function 1 is running, it will have to stop to run function 2 etc.

This sounds like code for a road crossing for a model railway. The usual millis techniques will easily take care of it as gcjr showed.

by test i assume you mean the condition.

as long as they are < msec, they allow the first event to occur resulting in an LED being turned on or a bell being struck and are then reset.

i'm not sure this is what you're looking for but serves as a starting point for discussion