Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumBugsWebsite,  Reference,  Examples Bugs › why the delay can't be used in interrupt?

Page Index Toggle Pages: 1
why the delay can't be used in interrupt? (Read 10839 times)
07/15/08 at 06:48:38

zouguokanguo   Offline
YaBB Newbies
I Love YaBB 2!

Posts: 6
*
 
Why the delay function can not be used in interrupt?

Call a function which includes a delay by attachInterrupt but doesn't work properly, why?
 
IP Logged
 
Reply #1 - 07/15/08 at 15:10:02

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
zouguokanguo,

Could you leae post your code.  I will make it easier for some to help you.

Thank you,
Vaccumdiode

 
IP Logged
 
Reply #2 - 07/15/08 at 20:51:54

Alan_Kilian   Offline
Full Member
Wiring? It looks like
Java to me.

Posts: 118
***
 
There's a timer generating interrupts which increments a "clock" variable.

The delay() routine waits until that clock variable gets to time+delay.

Interrupts are "disabled" when you are all ready inside an interrupt handler.

So, when you call delay() the clock variable never increments, and you
never get back out of the delay() routine.
 
IP Logged
 
Reply #3 - 07/16/08 at 05:14:44

zouguokanguo   Offline
YaBB Newbies
I Love YaBB 2!

Posts: 6
*
 
thank you very much for your help

my code is simply like this:

void setup()
{
    pinMode(1, INPUT);
    attachInterrupt(1, flash, RISING);
    pinMode(2, OUTPUT)
}

void loop()
{}

void flash()
{
    digitalWrite(2, HIGH);
    delay(1000);
    digitalWrite(2, LOW);
}

I basically want the LED which connects to pin 2 to blink when the pin 1 get from low to high.

Is there an alternative to use the timer or delay function (or something similar)during the interrupt ?

Thanks again for your help
 
IP Logged
 
Reply #4 - 07/17/08 at 15:33:12

roypardi   Offline
Junior Member
I Love YaBB 2!
Boston USA

Posts: 57
**
 
Set a variable == 1 in the interrupt routine and then in your loop check its value- if it has changed then do your delay, and  set the variable back to 0 to get ready for the next interrupt
 
IP Logged
 
Reply #5 - 07/18/08 at 08:04:06

zouguokanguo   Offline
YaBB Newbies
I Love YaBB 2!

Posts: 6
*
 
Thank you very much

I will try tomorrow

and I will appreciate if you can further provide a sample code.
 
IP Logged
 
Page Index Toggle Pages: 1