In programming, an interrupt is a signal to the processor emitted by hardware or software indicating 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 suspending 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 normal activities.
evive has 6 external interrupt pins: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), and 21 (interrupt 2). these pins can be configured to trigger an interrupt on a low level, a rising or falling edge, or a change in level.
In Arduino IDE environment you can attach interrupts using attachInterrupt() function. There are two different approaches you can initialize an interrupt pin:
attachInterrupt(digitalPinToInterrupt(pin), ISR, mode); attachInterrupt(interrupt, ISR, mode);
attachInterrupt(digitalPinToInterrupt(pin), ISR, mode);
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 referred as an interrupt service routine), and mode defines how the interrupt occurs. There are several types of mode listed in the table below:
When we don’t need any kind of interrupts we can detach it by using detachinterrupt
To detach an interrupt, you have to use detachInterrupt() function in Arduino IDE platform. There are two different ways to do it:
This program demonstrates the use of interrupts with evive.
You have to connect digital pins 2 and 7 using a jumper wire.
In this program, we will control and LED (connected to pin 13)
using pushbutton 1 of evive and interrupt pin