External interrupts

Interrupts are weird things in the Arduino world; however, they are immensely useful. So what are they? Interrupts signal to the microcontroller that something has happened and it needs to take some action. Basically they work like this: we can attach an interrupt to a digital pin. Whenever it detects a change, it will pause anything the microcontroller is doing, execute a function we tell it to execute, and then resume normal operation.

In this example, we will fade two LEDs using PWM and while that is happening, we will be able to select which LED is fading using the button connected to an interrupt.

Getting ready

Following are the ingredients needed for this recipe:

  • An Arduino board connected to a computer via USB
  • Jumper cables ...

Get Arduino Development Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.