Ramki
Ramki

Reputation: 381

Infinite loop outside of the loop() function

This is the pseudo code of my Arduino sketch for NodeMCU. It has an handler that updates the LED strip continuously.

void setup() {

}

void loop() {

}

bool handler() {
//intended infinite loop
}

The problem is that the infinite loop is blocking the main loop(). Is there a way that I can execute the infinite loop without blocking the main loop() function.

I am sorry my question is vague, I am only a beginner in Arduino programming.

Upvotes: 0

Views: 540

Answers (2)

TomServo
TomServo

Reputation: 7409

You should have only one "infinite" loop in your sketch, and it's already constructed for you, it's loop(). Every other loop -- or any function call, for that matter -- that you construct must have some way to exit and get back to loop(), preferably quickly. You could exit with a break or any other mechanism that returns control to loop(). But you must return...

Upvotes: 2

dont block the main loop instead let the loop to call the handler every time the function is called...

void setup()
{
    //setup required parameters/handlers
}

void loop()
{
    // a piece of code that calls the handler
    if(handler())
    {
        // TODDY
    }
}

bool handler()
{
    //intended infinite loop
}

Upvotes: 1

Related Questions