this library will let you attach a function to a pin using pin-change-interrupt, api is quite simple
https://github.com/neu-rah/PCINT#api
Arduino pin change interrupt library compatible with AVR and SAM with consistent interface.
Allows handlers to be called with a predefined cargo (void*) for user data or just regular void returning functions with no params.
This library use meta-programing to achieve consistency.
Example
#include <pcint.h>
#define led 13
#define btn 12
void setled() {
digitalWrite(led,digitalRead(btn));
}
void setup() {
pinMode(led,OUTPUT);
pinMode(btn,INPUT_PULLUP);
PCattachInterrupt<btn>(setled,CHANGE);
setled();//initial led status
}
void loop() {}
API
Just two methods:
void PCattachInterrupt<pin>(userFunc,mode);
void PCdetachInterrupt<pin>();