Go Down

Topic: Interrupting sequence (Read 504 times) previous topic - next topic

bs50

I have two sequnces coded as:

while(0)
{
a()

}
while(1)
{
b()

}

Both a() and b() use delay().  

I know attachInterrupt(int, a(), change) will cause delay() not to work, so how can I get around this? My question is, how can I interrupt a() or b() when my input 1 or 0 changes?

Coding Badly

#1
Mar 25, 2010, 06:12 am Last Edit: Mar 25, 2010, 06:13 am by bcook Reason: 1
Quote
know attachInterrupt(int, a(), change) will cause delay() not to work

In what way does delay not work?

For the best advice, describe your application.

Mitch_CA

Interrupts will still work while calling delay().  But delay() may end up being longer than you expect (due to time consumed inside an interrupt()).

bs50

I have a set of 4 RGB leds wired to pins 2-13 and a simple switch to pin 14.  

a() has a set of instructions (which only lasts a few seconds) to execute while the switch is off
b() has a set of instructions (which lasts for a few hours) to execute while the switch is on

I want to be able to switch between a() and b() once the switch state changes without waiting for a() or b() to complete their instructions.


Imahilus

The 'blink without delay' example comes to mind.
You'd probably want to check the switch every now and again during either procedure, delays might mess this up... interrupts won't be able to stop a procedure either, and if you set the procedures up so that if the switch isn't in the right position anymore, it exits the procedure.

Thus I reckon the best course of action would be to model both procedures after the 'blink without delay' example, with frequent checks of the switch.

Go Up