Reference.AttachInterrupt History

Hide minor edits - Show changes to output

November 23, 2013, at 08:41 AM by Scott Fitzgerald -
Changed lines 30-31 from:
Typically global variables are used to pass data between an ISR and the main program. To make sure variables used in an ISR are updated correctly, declare them as @@volitile@@.
to:
Typically global variables are used to pass data between an ISR and the main program. To make sure variables used in an ISR are updated correctly, declare them as @@volatile@@.
November 23, 2013, at 08:41 AM by Scott Fitzgerald -
Added lines 17-33:
!!!!Note
''Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function. See the section on ISRs below for more information.''

!!!! Using Interrupts
Interrupts are useful for making things happen automatically in microcontroller programs, and can help solve timing problems. Good tasks for using an interrupt may include reading a rotary encoder, or monitoring user input.

If you wanted to insure that a program always caught the pulses from a rotary encoder, so that it never misses a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred. Other sensors have a similar interface dynamic too, such as trying to read a sound sensor that is trying to catch a click, or an infrared slot sensor (photo-interrupter) trying to catch a coin drop. In all of these situations, using an interrupt can free the microcontroller to get some other work done while not missing the input.

!!!! About Interrupt Service Routines
ISRs are special kinds of functions that have some unique limitations most other functions do not have. An ISR cannot have any parameters, and they shouldn't return anything.

Generally, an ISR should be as short and fast as possible. If your sketch uses multiple ISRs, only one can run at a time, other interrupts will be ignored (turned off) until the current one is finished. as delay() and millis() both rely on interrupts, they will not work while an ISR is running. delayMicroseconds(), which does not rely on interrupts, will work as expected.

Typically global variables are used to pass data between an ISR and the main program. To make sure variables used in an ISR are updated correctly, declare them as @@volitile@@.

For more information on interrupts, see [[http://gammon.com.au/interrupts | Nick Gammon's notes]].
Deleted lines 77-91:
!!!!Note
''Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function. See the section on ISRs below for more information.''

!!!! Using Interrupts
Interrupts are useful for making things happen automatically in microcontroller programs, and can help solve timing problems. Good tasks for using an interrupt may include reading a rotary encoder, or monitoring user input.

If you wanted to insure that a program always caught the pulses from a rotary encoder, so that it never misses a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred. Other sensors have a similar interface dynamic too, such as trying to read a sound sensor that is trying to catch a click, or an infrared slot sensor (photo-interrupter) trying to catch a coin drop. In all of these situations, using an interrupt can free the microcontroller to get some other work done while not missing the input.

!!!! About Interrupt Service Routines
ISRs are special kinds of functions that have some unique limitations most other functions do not have. An ISR cannot have any parameters, and they shouldn't return anything.

Generally, an ISR should be as short and fast as possible. If your sketch uses multiple ISRs, only one can run at a time, other interrupts will be ignored (turned off) until the current one is finished. as delay() and millis() both rely on interrupts, they will not work while an ISR is running. delayMicroseconds(), which does not rely on interrupts, will work as expected.

Typically global variables are used to pass data between an ISR and the main program. To make sure variables used in an ISR are updated correctly, declare them as @@volitile@@.
November 23, 2013, at 08:39 AM by Scott Fitzgerald -
Changed lines 6-7 from:
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). The table below shows the available interrupt pins on various boards.
to:
Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs. Replaces any previous function that was attached to the interrupt. Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). The table below shows the available interrupt pins on various boards.
Changed lines 19-20 from:
(:cell width=400px:) attachInterrupt(interrupt, function, mode)
(:cellnr width=400px:) attachInterrupt(pin, function, mode)
to:
(:cell width=400px:) attachInterrupt(interrupt, ISR, mode)
(:cellnr width=400px:) attachInterrupt(pin, ISR, mode)
Changed lines 34-36 from:
(:cellnr width=150px:) '''function''':
(:cell width=240px:) the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an ''interrupt service routine.''
to:
(:cellnr width=150px:) '''ISR''':
(:cell width=240px:) the ISR to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an ''interrupt service routine.''
Changed lines 62-63 from:
''Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function.''
to:
''Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function. See the section on ISRs below for more information.''
Added lines 69-75:
!!!! About Interrupt Service Routines
ISRs are special kinds of functions that have some unique limitations most other functions do not have. An ISR cannot have any parameters, and they shouldn't return anything.

Generally, an ISR should be as short and fast as possible. If your sketch uses multiple ISRs, only one can run at a time, other interrupts will be ignored (turned off) until the current one is finished. as delay() and millis() both rely on interrupts, they will not work while an ISR is running. delayMicroseconds(), which does not rely on interrupts, will work as expected.

Typically global variables are used to pass data between an ISR and the main program. To make sure variables used in an ISR are updated correctly, declare them as @@volitile@@.
November 19, 2013, at 11:06 AM by Cristian -Vacuum- Maglie -
Changed lines 9-14 from:
||'''Board''' || '''int.0''' || '''int.1''' || '''int.2''' || '''int.3''' || '''int.4''' || '''int.5''' ||
||Uno, Ethernet || 2 || 3 ||
||Mega2560 || 2 || 3 || 21 || 20 || 19 || 18 ||
||Leonardo || 3 || 2 || 0 || 1 || 7 ||
||Due || '''(see below)''' ||||||||||||
to:
||'''Board''' || '''int.0''' || '''int.1''' || '''int.2''' || '''int.3''' || '''int.4''' || '''int.5''' ||
||Uno, Ethernet || 2 || 3 || || || || ||
||Mega2560 || 2 || 3 || 21 || 20 || 19 || 18 ||
||Leonardo || 3 || 2 || 0 || 1 || 7 || ||
||Due || '''(see below)''' ||||||||||||
May 13, 2013, at 09:13 PM by Federico -
Changed line 12 from:
||Leonardo || 3 || 2 || 0 || 1 ||
to:
||Leonardo || 3 || 2 || 0 || 1 || 7 ||
November 12, 2012, at 10:53 AM by Cristian -Vacuum- Maglie -
Changed lines 13-14 from:
||Due '''(see below)''' ||
to:
||Due || '''(see below)''' ||||||||||||
November 11, 2012, at 02:58 PM by Scott Fitzgerald -
November 11, 2012, at 02:56 PM by Scott Fitzgerald -
Changed lines 6-9 from:
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. The Arduino Uno has two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3).

The table below shows the available interrupt pins on various Arduino boards.
to:
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). The table below shows the available interrupt pins on various boards.
Changed lines 15-16 from:
The Arduino Due board has powerful interrupt capabilities that allows you to attach, potentially, an interrupt function on all available pins. Thus, with the Due only, you can specify directly the pin number in attachInterrupt.
to:
The Arduino Due board has powerful interrupt capabilities that allows you to attach an interrupt function on all available pins. You can directly specify the pin number in attachInterrupt().
Changed lines 65-68 from:
Interrupts are useful for making things happen automatically in microcontroller programs, and can help solve timing problems. A good task for using an interrupt might be reading a rotary encoder, monitoring user input.

If you wanted to insure that a program always caught the pulses from a rotary encoder, never missing a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred. Other sensors have a similar interface dynamic too, such as trying to read a sound sensor that is trying to catch a click, or an infrared slot sensor (photo-interrupter) trying to catch a coin drop. In all of these situations, using an interrupt can free the microcontroller to get some other work done while not missing the doorbell.
to:
Interrupts are useful for making things happen automatically in microcontroller programs, and can help solve timing problems. Good tasks for using an interrupt may include reading a rotary encoder, or monitoring user input.

If you wanted to insure that a program always caught the pulses from a rotary encoder, so that it never misses a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred. Other sensors have a similar interface dynamic too, such as trying to read a sound sensor that is trying to catch a click, or an infrared slot sensor (photo-interrupter) trying to catch a coin drop. In all of these situations, using an interrupt can free the microcontroller to get some other work done while not missing the input.
Changed lines 70-71 from:

[@int pin = 13;
to:
(:source lang=arduino tabwidth=4:)
int pin = 13;
Changed lines 89-90 from:
@]
to:
(:sourceend:)
November 11, 2012, at 11:59 AM by Cristian -Vacuum- Maglie -
Changed lines 11-16 from:
||'''Board''' ||'''interrupt 0''' ||'''interrupt 1''' ||'''interrupt 2''' ||'''interrupt 3''' ||'''interrupt 4''' ||'''interrupt 5'''
||Uno, Ethernet ||2 ||3
||Mega2560 ||2 ||3 ||21 ||20 ||19 ||18
||Leonardo ||3 ||2 ||0 ||1

to:
||'''Board''' || '''int.0''' || '''int.1''' || '''int.2''' || '''int.3''' || '''int.4''' || '''int.5''' ||
||Uno, Ethernet || 2 || 3 ||
||Mega2560 || 2 || 3 || 21 || 20 || 19 || 18 ||
||Leonardo || 3 || 2 || 0 || 1 ||
||Due '''(see below)''' ||

The Arduino Due board has powerful interrupt capabilities that allows you to attach, potentially, an interrupt function on all available pins. Thus, with the Due only, you can specify directly the pin number in attachInterrupt.
Changed lines 20-21 from:
attachInterrupt(interrupt, function, mode)
to:
(:table border=0 cellpadding=5 cellspacing=0 width=80%:)
(:cell width=400px:) attachInterrupt(interrupt, function, mode)
(:cellnr width=400px:) attachInterrupt(pin, function, mode)
(:cell:) (''Arduino Due only'')
(:tableend:)
Changed lines 28-32 from:
'''interrupt''': the number of the interrupt (''int'')

'''function''': the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an ''interrupt service routine.''

'''mode''' defines when the interrupt should be triggered. Four contstants are predefined as valid values:
to:
(:table border=0 cellpadding=5 cellspacing=0 width=80%:)
(:cell width=150px:) '''interrupt''':
(:cell width=240px:) the number of the interrupt (''int'')

(:cellnr width=150px:) '''pin''':
(:cell width=240px:) the pin number
(:cell:)(''Arduino Due only'')

(:cellnr width=150px:) '''function''':
(:cell width=240px:) the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an ''interrupt service routine.''

(:cellnr width=150px:) '''mode''':
(:cell width=240px:)
defines when the interrupt should be triggered. Four contstants are predefined as valid values:
Added lines 47-58:
(:cellnr width=150px:)
(:cell width=240px:)
The Due board allows also:

(:cellnr width=150px:)
(:cell width=240px:)
* '''HIGH''' to trigger the interrupt whenever the pin is high.
(:cell:)(''Arduino Due only'')

(:tableend:)

October 22, 2012, at 04:25 PM by Federico -
Changed lines 11-16 from:
||'''Board''' ||'''interrupt pin (interrupt number)'''
||Uno ||D2(0), D3(1)
||Mega2560 ||D2(0), D3(1), D21(2), D20(3), D19(4), D18 (5)
||Leonardo ||D3(0), D2(1), D0(2), D1(3)

to:
||'''Board''' ||'''interrupt 0''' ||'''interrupt 1''' ||'''interrupt 2''' ||'''interrupt 3''' ||'''interrupt 4''' ||'''interrupt 5'''
||Uno, Ethernet ||2 ||3
||Mega2560 ||2 ||3 ||21 ||20 ||19 ||18
||Leonardo ||3 ||2 ||0 ||1

October 11, 2012, at 09:58 PM by Scott Fitzgerald -
Changed lines 8-9 from:
The table below shows the available interrupt pins on the other Arduino boards.
to:
The table below shows the available interrupt pins on various Arduino boards.
October 11, 2012, at 09:57 PM by Scott Fitzgerald -
Changed lines 6-7 from:
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. The Arduino Uno has two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). The following table show the available interrupt pins on the other Arduino boards.
to:
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. The Arduino Uno has two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3).

The table below shows the available interrupt pins on the other Arduino boards.
September 26, 2012, at 05:52 PM by Federico -
Changed lines 6-7 from:
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). The Arduino Mega has an additional four: numbers 2 (pin 21), 3 (pin 20), 4 (pin 19), and 5 (pin 18).
to:
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. The Arduino Uno has two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). The following table show the available interrupt pins on the other Arduino boards.

||border=0 style="border-collapse:collapse" cellpadding=5 width=90%
||'''Board''' ||'''interrupt pin (interrupt number)'''
||Uno ||D2(0), D3(1)
||Mega2560 ||D2(0), D3(1), D21(2), D20(3), D19(4), D18 (5)
||Leonardo ||D3(0), D2(1), D0(2), D1(3)

June 02, 2012, at 10:55 PM by David A. Mellis -
Changed lines 1-3 from:
!!attachInterrupt(interrupt, function, mode)

to:
!!attachInterrupt()

Added lines 8-10:
!!!!Syntax
attachInterrupt(interrupt, function, mode)
May 27, 2009, at 02:38 PM by David A. Mellis -
Changed lines 6-7 from:
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. Most Arduino boards have two external interrupts: 0 (on digital pin 2) and 1 (on digital pin 3). The Arduino Mega has an additional four: numbers 2 (pin 21), 3 (pin 20), 4 (pin 19), and 5 (pin 18).
to:
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). The Arduino Mega has an additional four: numbers 2 (pin 21), 3 (pin 20), 4 (pin 19), and 5 (pin 18).
May 27, 2009, at 02:37 PM by David A. Mellis -
Changed lines 6-7 from:
Specifies a function to call when external interrupt 0 or 1 occurs, on digital pin 2 or 3, respectively. Replaces any previous function that was attached to the interrupt.
to:
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. Most Arduino boards have two external interrupts: 0 (on digital pin 2) and 1 (on digital pin 3). The Arduino Mega has an additional four: numbers 2 (pin 21), 3 (pin 20), 4 (pin 19), and 5 (pin 18).
Changed lines 10-11 from:
'''interrupt''': the number of the interrupt (''int''): 0 or 1.
to:
'''interrupt''': the number of the interrupt (''int'')
August 01, 2008, at 10:17 PM by David A. Mellis -
Changed lines 6-9 from:
Specifies a function to call when external interrupt 0 or 1 occurs, on digital pin 2 or 3, respectively.

'''Note''': ''Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function.''
to:
Specifies a function to call when external interrupt 0 or 1 occurs, on digital pin 2 or 3, respectively. Replaces any previous function that was attached to the interrupt.
Changed lines 10-14 from:
'''interrupt:''': the number of the interrupt (''int''): 0 or 1.

'''function:''': the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an ''interrupt service routine.''

'''mode:''' defines when the interrupt should be triggered. Four contstants are predefined as valid values:
to:
'''interrupt''': the number of the interrupt (''int''): 0 or 1.

'''function''': the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an ''interrupt service routine.''

'''mode''' defines when the interrupt should be triggered. Four contstants are predefined as valid values:
Added lines 24-26:
!!!!Note
''Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function.''
May 12, 2008, at 06:43 PM by David A. Mellis -
Changed lines 6-12 from:
attchInterrupt enables interrupts 0 or 1, on digital pins 2 or 3 respectively. It also specifies the function to call when an external interrupt occurs.


'''Note''': '''millis'''() ''and'' '''delay'''() ''won't work in your interrupt-handling function. Any'' '''serial data''' ''received while in your interrupt-handling function will be lost.''

You also should declare as'' '''volatile''' ''any variables that you modify within your interrupt handling function (see the example).''
to:
Specifies a function to call when external interrupt 0 or 1 occurs, on digital pin 2 or 3, respectively.

'''Note''': ''Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function.''
Changed lines 12-13 from:
'''interrupt:''': the number of the interrupt (''int''), with a valid value of 0 or 1.
to:
'''interrupt:''': the number of the interrupt (''int''): 0 or 1.
Deleted lines 30-31:
Interrupts can be used with internal hardware too, such as timers, but as of Arduino 008, this requires AVR code and is not supported in the Arduino core.
July 27, 2007, at 04:20 AM by Paul Badger -
Changed lines 32-33 from:
If you wanted to insure that a program always caught the pulses from a rotary encoder, never missing a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred. Other sensors have a similar interface dynamic too, such as trying to read a sound sensor which it trying to catch a click, or an infrared slot sensor (photo-interrupter) trying to catch a coin drop. In all of these situations, using an interrupt can free the microcontroller to get some other work done while not missing the doorbell.
to:
If you wanted to insure that a program always caught the pulses from a rotary encoder, never missing a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred. Other sensors have a similar interface dynamic too, such as trying to read a sound sensor that is trying to catch a click, or an infrared slot sensor (photo-interrupter) trying to catch a coin drop. In all of these situations, using an interrupt can free the microcontroller to get some other work done while not missing the doorbell.
June 17, 2007, at 05:33 AM by Paul Badger -
Changed lines 6-8 from:
attchInterrupt enables interrupt 0 or 1, on digital pins 2 and 3 respectively. It also specifies the function to call when an external interrupt occurs.

to:
attchInterrupt enables interrupts 0 or 1, on digital pins 2 or 3 respectively. It also specifies the function to call when an external interrupt occurs.

June 17, 2007, at 05:31 AM by Paul Badger -
Changed lines 32-37 from:
If you wanted to insure that a program always caught the pulses from a rotary encoder, never missing a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly "listen" for the encoder, in order to catch pulses when they occured.




to:
If you wanted to insure that a program always caught the pulses from a rotary encoder, never missing a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred. Other sensors have a similar interface dynamic too, such as trying to read a sound sensor which it trying to catch a click, or an infrared slot sensor (photo-interrupter) trying to catch a coin drop. In all of these situations, using an interrupt can free the microcontroller to get some other work done while not missing the doorbell.

Interrupts can be used with internal hardware too, such as timers, but as of Arduino 008, this requires AVR code and is not supported in the Arduino core.
June 13, 2007, at 05:37 AM by Paul Badger -
Changed lines 17-18 from:
'''function:''': the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as the interrupt service routine.
to:
'''function:''': the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an ''interrupt service routine.''
June 13, 2007, at 05:36 AM by Paul Badger -
Changed line 19 from:
'''mode:''' when the interrupt should be triggered. Four contstants are predefined as valid values:
to:
'''mode:''' defines when the interrupt should be triggered. Four contstants are predefined as valid values:
June 13, 2007, at 05:35 AM by Paul Badger -
Changed line 19 from:
'''mode:''' when the interrupt should be triggered:
to:
'''mode:''' when the interrupt should be triggered. Four contstants are predefined as valid values:
June 13, 2007, at 05:32 AM by Paul Badger -
Changed lines 15-18 from:
'''interrupt''': the number of the interrupt (''int''), with a valid value of 0 or 1.

'''function''': the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as the interrupt service routine.
to:
'''interrupt:''': the number of the interrupt (''int''), with a valid value of 0 or 1.

'''function:''': the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as the interrupt service routine.
Added lines 29-37:
!!!! Using Interrupts
Interrupts are useful for making things happen automatically in microcontroller programs, and can help solve timing problems. A good task for using an interrupt might be reading a rotary encoder, monitoring user input.

If you wanted to insure that a program always caught the pulses from a rotary encoder, never missing a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly "listen" for the encoder, in order to catch pulses when they occured.




June 13, 2007, at 05:23 AM by Paul Badger -
Changed lines 15-19 from:
interrupt: the number of the interrupt (''int''), with a valid value of 0 or 1.

function: the function to call when the interrupt occurs; this function must take no parameters and return nothing.

mode: when the interrupt should be triggered:
to:
'''interrupt''': the number of the interrupt (''int''), with a valid value of 0 or 1.

'''function''': the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as the interrupt service routine.

'''mode:''' when the interrupt should be triggered:
June 13, 2007, at 05:21 AM by Paul Badger -
Changed lines 15-16 from:
interrupt: the number of the interrupt (''int'')
to:
interrupt: the number of the interrupt (''int''), with a valid value of 0 or 1.
Changed lines 19-20 from:
mode: when the interrupt should be triggered: '''LOW''' to trigger the interrupt whenever the pin is low, '''CHANGE''' to trigger the interrupt whenever the pin changes value, '''RISING''' to trigger when the pin goes from low to high, and '''FALLING''' for when the pin goes from high to low.
to:
mode: when the interrupt should be triggered:
* '''LOW''' to trigger the interrupt whenever the pin is low,
*'''CHANGE''' to trigger the interrupt whenever the pin changes value
* '''RISING''' to trigger when the pin goes from low to high,
* '''FALLING''' for when the pin goes from high to low.
June 13, 2007, at 05:19 AM by Paul Badger -
Changed lines 6-7 from:
Specifies the function to call when an external interrupt occurs. There are two external interrupts (0 and 1), on digital pins 2 and 3 respectively.
to:
attchInterrupt enables interrupt 0 or 1, on digital pins 2 and 3 respectively. It also specifies the function to call when an external interrupt occurs.

Changed lines 11-12 from:
'''Note''': ''you may need to declare as'' '''volatile''' ''any variables that you modify within your interrupt handling function (see the example).''
to:
You also should declare as'' '''volatile''' ''any variables that you modify within your interrupt handling function (see the example).''
May 03, 2007, at 07:31 AM by David A. Mellis -
Added lines 10-11:
'''Note''': ''you may need to declare as'' '''volatile''' ''any variables that you modify within your interrupt handling function (see the example).''
Changed lines 27-28 from:
int state = LOW;
to:
volatile int state = LOW;
Added line 37:
digitalWrite(pin, state);
Deleted line 42:
digitalWrite(pin, state);
March 12, 2007, at 08:03 AM by David A. Mellis -
Changed lines 8-9 from:
'''Note''': '''millis'''() ''and'' '''delay'''() ''won't work in your interrupt-handling function. Any serial data received while in your interrupt-handling function will be lost.''
to:
'''Note''': '''millis'''() ''and'' '''delay'''() ''won't work in your interrupt-handling function. Any'' '''serial data''' ''received while in your interrupt-handling function will be lost.''
March 12, 2007, at 07:53 AM by David A. Mellis -
Added lines 8-9:
'''Note''': '''millis'''() ''and'' '''delay'''() ''won't work in your interrupt-handling function. Any serial data received while in your interrupt-handling function will be lost.''
December 02, 2006, at 05:09 PM by David A. Mellis -
Changed line 22 from:
[@ int pin = 13;
to:
[@int pin = 13;
December 02, 2006, at 05:09 PM by David A. Mellis -
Changed lines 22-23 from:
[@
int pin = 13;
to:
[@ int pin = 13;
December 02, 2006, at 05:08 PM by David A. Mellis -
Added lines 22-42:
[@
int pin = 13;
int state = LOW;

void setup()
{
pinMode(pin, OUTPUT);
attachInterrupt(0, blink, CHANGE);
}

void loop()
{
}

void blink()
{
state = !state;
digitalWrite(pin, state);
}
@]
December 02, 2006, at 05:05 PM by David A. Mellis -
Added lines 1-24:
!!attachInterrupt(interrupt, function, mode)


!!!!Description

Specifies the function to call when an external interrupt occurs. There are two external interrupts (0 and 1), on digital pins 2 and 3 respectively.

!!!!Parameters

interrupt: the number of the interrupt (''int'')

function: the function to call when the interrupt occurs; this function must take no parameters and return nothing.

mode: when the interrupt should be triggered: '''LOW''' to trigger the interrupt whenever the pin is low, '''CHANGE''' to trigger the interrupt whenever the pin changes value, '''RISING''' to trigger when the pin goes from low to high, and '''FALLING''' for when the pin goes from high to low.

!!!!Returns

none

!!!!Example

!!!!See also

* [[detachInterrupt]]

Share