Book Image

Arduino Development Cookbook

By : Cornel M Amariei
Book Image

Arduino Development Cookbook

By: Cornel M Amariei

Overview of this book

Table of Contents (16 chapters)
Arduino Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 and a breadboard

  • Two standard LEDs

  • Two resistors between 220–1,000 ohm

  • A push button

How to do it…

The following are the steps to connect the two LEDs and the button:

  1. Connect the two LEDs to the breadboard and connect their negative terminals together...