You can use attachInterupt()
with CHANGE
to trigger on both RISING
and FALLING
flanks.
#define INTERRUPT_PIN 13 // Choose any pin with interrupt functionality here. void myInterrupt() { // TODO Your code goes here. } void setup() { attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), myInterrupt, CHANGE); }