Book Image

Arduino Essentials

Book Image

Arduino Essentials

Overview of this book

Table of Contents (17 chapters)
Arduino Essentials
About the Author
About the Reviewer

The concept of an interruption

As you may have intuited, an interrupt is a special mechanism the CPU incorporates to have a direct channel to be noticed when some event occurs.

Most Arduino microcontrollers have two of these:

  • Interrupt 0 on digital pin 2

  • Interrupt 1 on digital pin 3

But some models, such as the Mega2560, come with up to five interrupt pins.

Once an interrupt has been notified, the CPU completely stops what it was doing and goes on to look at it, by running a special dedicated function in our code called Interrupt Service Routine (ISR).

When I say that the CPU completely stops, I mean that even functions such as delay() or millis() won't be updated while the ISR is being executed.

Interrupts can be programmed to respond on different changes of the signal connected to the corresponding pin and thus the Arduino language has four predefined constants to represent each of these four modes:

  • LOW: It will trigger the interrupt whenever the pin gets a LOW value

  • CHANGE: The interrupt will...