Go Down

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


I have two sequnces coded as:




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

Mar 25, 2010, 06:12 am Last Edit: Mar 25, 2010, 06:13 am by bcook Reason: 1
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.


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


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.


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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131