Need delay() in interrupt function. How?

I have the same question too. I want a delay after a button is pressed, nut that delay needs to be precisely 300ms. Using the delay(300) function would give a rough delay of 300ms. So is there anyway to achieve the delay without using the delay function?

Split from a very old thread

Are you using an interrupt to detect the button press and, if so, why ?

As for timing, take a look at Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE but do not use the millis() function in an interrupt

Arduino Uno working Code:

bool runINT = false;
void setup() {
//interrupt routine definition pins to Function what to do when they hit
attachInterrupt(0, funcInterrupt1, FALLING); //PIN2
}

void loop() {
if(runINT==true){
delay(300);
runINT=false; //Unlock delay again if interrupt comes in again
}else
//other code that takes way less than delay(anyMiliseconds);
...
}

void funcInterrupt1() {
runINT = true;
}

UKHeliBob:
Split from a very old thread

Are you using an interrupt to detect the button press and, if so, why ?

I have an external interrupt on INT0 pin so I don't have to search it in the loop by polling.
Here is an example of what I want but without the delay. The button is pulled low in the interrupt ISR.

Code:
void loop() {
if(button==LOW){
delay(300);
}

//rest of code

}

I have an external interrupt on INT0 pin so I don't have to search it in the loop by polling.

If you are going to set a flag in the ISR indicating that the ISR has been triggered then react to the flag in loop() then you might just as well read the input in loop() unless your loop() code is so slow that polling is not appropriate. If that is the case then you need to address why loop() is too slow

Please provide a full example of what you are trying to do.

Did you look at the links I posted ?

"The button is pulled low in the interrupt ISR."

you mean: pull an output low in the interrupt routine and then need to wait 300ms?

Tip: Make the ISR Routine short as possible and style the main loop the way if the interrupt hits you react to it on top of the routine..

Your main programm should not take a very long time, so if isr hits you return to where you are on the main programm and on top of it you pull the output low and run the delay only if isr was there..

You should NEVER have a delay inside an ISR. The code in your ISR should complete as quickly as possible - even 100 microsecs would be a long time for an ISR.

...R

Clarify the requirements and explain how long the loop needs to take a spin.

Processes operated by humans pressing buttons are rarely in need of micro second reaction time. Even at a few millisecond it will feel real time to the end user

ahsan317:
I have an external interrupt on INT0 pin so I don't have to search it in the loop by polling.
Here is an example of what I want but without the delay. The button is pulled low in the interrupt ISR.

Code:
void loop() {
if(button==LOW){
delay(300);
}

//rest of code

}

Questions like this come up often, search these fora and find them an the answers.

You should not use interrupts for detecting button presses. You should be using millis to create delays. There are lots and lots of examples in answers on this site for what you need to do, here are some suggestions to get you started:
de-bounce tutorial
Using millis for timing
Demonstration for several things at the same time

There's plenty of other information that is relevant to what you are doing, just apply your digits to your HID and do some searching.

Thanks for the links, I was able to solve my problem.

I was able to solve my problem.

You never said what it was.

For the benefit of people finding this thread in the future can you please describe the problem and the solution

i don't think it's that uncommon for an event to require a delayed response

capture the time when the event occurs and when captured wait for some time to have expired to perform the action.

wait for some time to have expired to perform the action.

but do not block the free execution of the loop() function