Interrupts

Categories: , , ,

Intro

Interrupts are useful for automatically executing things in microcontroller programs and can solve timing problems. Good tasks for using an interrupt may include reading a rotary encoder or monitoring user input.
The Arduino Uno has 2 and the Mega has 6 external interrupt pins available:

  • Arduino Uno/Controllino MINI/INT.x interrupt:                   2/IN0/INT.0  –  3/IN1/INT.1 
  • Arduino Mega/Controllino MAXI,MEGA/INT.x interrupt: 2/D0/INT.0  –  3/D1/INT.1  –  18/IN0/INT.5  –  19/IN1/INT.4  –  20/SDA/INT.3  –  21/SCL/INT.2

On the other hand the pin change interrupts can be enabled on many more pins.

Hardware Required

  • Controllino MINI/MAXI/MEGA
  • 12/24V DC Power supply

Circuit

Note*
Pin header is working on 5V TTL levels. Voltage levels over 5.5V can damage the Controllino permanently.

Code

Controllino MINI/MAXI/MEGA

#include <Controllino.h>

const byte digital_output = CONTROLLINO_D0;
const byte interruptPin = CONTROLLINO_IN1;
volatile byte state = LOW;

void setup() {
 pinMode(digital_output, OUTPUT);
 pinMode(interruptPin, INPUT);
 attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}

void loop() {
 digitalWrite(digital_output, state);
}

void blink() {
 state = !state;
}

Share This Post

More Tutorials to explore

Modbus TCP Master Client I/O

This is an example guide to setting up Modbus TCP communication between a client and server using CONTROLLINO and an Ethernet shield. This tutorial will

Modbus RTU Master Slave I/O

Introduction This tutorial will guide you through setting up Modbus RTU communication between a master and a slave device using two CONTROLLINO devices. The master device reads digital and analog inputs from the slave and sends