colastar
colastar

Reputation: 13

Arduino interupt a delay function

in my next project i use 4 Leds with delay(10000). I need a function for cancel this loop and start again with a new delay value e.g. 100.

I have enabled interrupts and when i pressed a button, delay changed to 100 AFTER a round. I have to wait 10 seconds.. It is possible to restart the loop function with the new values?

Upvotes: 0

Views: 1200

Answers (1)

djUniversal
djUniversal

Reputation: 624

Wow that was rude ignacio At least be helpful.

You can do this but not as you have implemented.

Delay is not good to be used in this circumstance. A much better way of implementing is to use a while loop like this:

int delayLED = 10000;

int beginMillis = millis();

while( millis() - beginMillis < delayLED)
{
    // insert the code for your "interrupt" here
    // kinda like this
    if(button pressed)
    {
        delayLED = 100;
        break;
    }
}

This is just a template not a complete answer. Let me know if you have further questions.

Happy coding!

Upvotes: 1

Related Questions