attachinterrupt limitation??

Hey, does anyone know when version 0012 comes out and if so will it fix the problem of not being
able to run the delay() function inside of attachinterrupt()???
Thanks
Jose

I doubt it would be a good idea to run the delay() function inside an interrupt handler.

delay() doesn't work in an interrupt because new interrupts are blocked while an existing interrupt is being handled, and delay relies on an interrupt for its timing.

Things can get very messy very quickly if interrupts are allowed to occur within other interrupts, and it can be very difficult to debug code that allows this.

Perhaps if you say what you want to achieve in your application someone can suggest some ideas that provide the functionality you need.

It’s easy enough for you to write your own delay that doesn’t rely on millis() and hence isn’t driven by an ISR. For example, you can just put:

#include <util/delay.h>

void delay_ms(unsigned int time)
{
while (time–)
_delay_ms(1);
}

in your program and call delay_ms() from within your ISR (interrupt service routine). That said, your goal should generally be to keep your ISRs as fast as possible, so I’d strongly recommend considering an alternative to delaying code execution while in one.

  • Ben

I'd like to hear more about the application. I can't think of a good example of when it would be a good idea to have a delay in an interrupt handler. As Bens says, interrupt handlers should be as short as possible.

Ben thanks. I am new to arduino and having lots of fun! The interrupt is used in a blinker control module! Thanks Rico

Use a static variable in the interrupt handler to store the current status. Have have the interrupt occur every time the blinker status needs to change. Then all your handler has to do is check and then change the status and toggle the blinker.