Arduino Playground is read-only starting December 31st, 2018. For more info please look at this Forum Post

PinChangeInt Library

What's New? Nov. 16, 2012: Version 2.17beta has been released.This release incorporates a number of recent changes, including: 2.15beta: The attachInterrupt() function now allows the user to change user function pointers. 2.13 beta: Major bugfix over previous versions. Look at the Release Notes for the download or read the RELEASE NOTES file in the zipfile for more information. Further information and the library are located in the Google Code Group.

Beginning Version 1.81beta, the library contains MEGA support, although there are some gotchas. Read the release notes and wiki for more info.

The PinChangeInt library implements Pin Change interrupts for the Arduino environment. It is a drop in replacement for the PCint library. This library was designed for the Arduino Uno/Duemilanove, and has been reported to work fine on the Nano, but it has not been tested there. As mentioned above, MEGA support is included but support for that platform is weak.

What are Pin Change interrupts? The ATmega processor at the heart of the Arduino has two different kinds of interrupts: “external”, and “pin change”. There are only two external interrupt pins, INT0 and INT1, and they are mapped to Arduino pins 2 and 3. These interrupts can be set to trigger on RISING or FALLING signal edges, or on low level. The triggers are interpreted by hardware, and the interrupt is very fast. On the other hand there are only 2 such pins on the ATmega328p in the Arduino Uno and Duemilanove.

On the other hand the pin change interrupts can be enabled on any or all of the Arduino's signal pins (Uno/Duemilanove/Nano). They are triggered equally on RISING or FALLING signal edges, so it is up to the interrupt code to set the proper pins to receive interrupts, to determine what happened (which pin? ...did the signal rise, or fall?), and to handle it properly. Furthermore, the pin change interrupts are grouped into 3 “port”s on the MCU, so there are only 3 interrupt vectors (subroutines) for the entire body of 20 pins. This makes the job of resolving the action on a single interrupt even more complicated. The interrupt routine should be fast, but complication is the enemy of speed. The PinChangeInt? library is designed to handle the Arduino's pin change interrupts as quickly and reasonably as possible.

Version 1.4 puts all the code in the .h file, to allow the programmer to configure it through their sketch for minimum ram usage. In earlier versions, it must be configured through the PinChangeIntConfig? header file instead.

To download the current version, more documentation or to report bugs please check out our Google Code Group

For example sketches see