void loop

is it possible to have more than 1 void loop? Asking for a friend -

No.

If you think you need more than one, you’re looking at a problem incorrectly.

Yes, as long as the function signature on the second is different.

But I suspect that's not what you're actually asking and that reply #1 nailed it.

As already told, no. Create 2 functions, loop1() and loop2(), and call them from loop().

bbishop:
is it possible to have more than 1 void loop? Asking for a friend -

No, but what would your friend want them to do if you could ?

bbishop:
is it possible to have more than 1 void loop? Asking for a friend -

I have one on each of my Arduino UNO's and NANO's and one on each of my ESP's.
so, I guess you can have lots of them.
maybe I did not understand the question ?

Maybe your friend needs something like Demonstration code for several things at the same time.

is it possible to have more than 1 void loop? Asking for a friend -

Despite what I said earlier in this thread it is, in fact, possible to have more than void loop() function in a program, but I am sure that is not the real question so follow sterretj's advice and look at the thread he linked to or tell us the real question

YES YOU CAN!

Write a base class "idler" that can links itself into a dynamic linked list with others of its kind.
In this base class, create a virtual method..

virtual void idle(void);

And.. A method to hook it into a linked list.

void hookup(void);

Now, create a global pointer to type idler.

idler* ourIdlers = NULL;

Create a global function "void idle(void)" that starts at the top of this list and calls idle() method for each object in your global list.

void idle(void) {

idle* trace;
trace = ourIdlers;
while(trace) {
trace->idle();
trace = trace->next;
}
}

Call the global idle() as the first thing in your loop.

void loop(void) {

idle();
// do the rest the rest of your stuff.
}

Now you can inherit this idler object, and each instance has a little private piece of loop() in it.

A) Early on in your idler code you need to call hookup(); to get linked in the the idler queue, then..
B) You write what you would like to do in your own private idle() method.

This makes all the "do many-things-at-once coding almost trivial.

Mostly, not always, but mostly, you can forget worrying about writing interrupt handling code as well. Just keep your idle loop running free and you can use it for blinking lights, filling buffers from disks.. Running servos..

Its indispensable for writing GUI code without having your brain explode managing all the onscreen bits.

-jim lee

Yes but there is still only one loop function after all that.

Its all fantasy anyway! If it feels like multiple loops, it IS!

-jim lee