How to use evive’s Interrupt pins

evive Fritzing
About This Tutorial
This tutorial discusses what are interrupts, and how to use evive’s interrupt pins in Arduino IDE with the help of an Arduino IDE sketch.
Tutorial Info

Components Required

ImageComponentQuantityAvailable in Kit
evive1
USB A-B Cable1

Introduction

In programming, an interrupt is a signal that a hardware or software sends to the processor alerting it of an event that needs immediate attention. An interrupt alerts the processor to a high-priority condition requiring the interruption of the current code the processor is executing. The processor responds by stopping all of its current activities, saving its state, and executing a function called an interrupt handler (or an interrupt service routine, ISR) to deal with the event. This interruption is temporary, and, after the interrupt handler finishes, the processor resumes its normal activities.

evive has 6 external interrupt pins:

  • 2 (interrupt 0)
  • 3 (interrupt 1)
  • 18 (interrupt 5)
  • 19 (interrupt 4)
  • 20 (interrupt 3)
  • 21 (interrupt 2)

These pins can be configured to trigger an interrupt on a LOW level, a rising or falling edge of a PWM signal, or a change in level.

attachInterrupt()

In Arduino IDE environment you can attach interrupts using the attachInterrupt() function. There are two different approaches with which you can initialise an interrupt pin:

attachInterrupt(digitalPinToInterrupt(pin), ISR, mode); 

AND

attachInterrupt(interrupt, ISR, mode);

where

  •  interrupt is the number of the interrupt pin (from 0-5)
  • pin is the pin number
  • ISR is the function that you call when interrupt occurs (this function do not take parameters, and returns nothing. This function is also called an interrupt service routine)
  • mode defines how the interrupt occurs.

There exist several modes, as shown in the table below:

Trigger TypeTrigger Action
LOWTrigger the interrupt whenever the pin is low
CHANGETrigger the interrupt whenever the pin value changes
RISINGTrigger when the pin goes from low to high
FALLINGTrigger when the pin goes from high to low

detachInterrupt()

When we don’t need any kind of interrupt we can stop it, or override it by using the detachInterrupt() function. There are two ways to use it:

detachInterrupt(interrupt); 

AND

detachInterrupt(digitalPinToInterrupt(pin));

Example

This example demonstrates the use of interrupts in evive. For this, you must connect digital pins 2 and 7 using a jumper wire. In this program, we will control the Pin 13 LED using evive’s push button 1, i.e. tactile switch 1, and interrupt pin.

Below is the Arduino IDE sketch:

This helped
This didn't help
Share this Tutorial
Share on facebook
Facebook
Share on twitter
Twitter
Share on google
Google+
Share on pinterest
Pinterest
Share on reddit
Reddit
Share on print
Print
Related Projects & Tutorials
All articles loaded
No more articles to load
Featured Projects
DIY Pinball Game Machine
IntroductionAnd we’re back to make your weekend merrier with another one of the most popular…
Arcade-Basketball-Game
DIY Arcade Basketball Game
Introduction“We don’t stop playing because we grow old; we grow old because we stop playing.”…
All articles loaded
No more articles to load
Close Menu
×

Cart