Pages: [1]   Go Down
Author Topic: Interrupting sequence  (Read 403 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 178
Posts: 12289
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: March 25, 2010, 12:13:01 am by bcook » Logged

Waterloo, Canada
Offline Offline
Full Member
***
Karma: 1
Posts: 242
Engineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Holland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 439
Arduino likes cookies too
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: