I’ve just quickly knocked this up and tested it. In my case pin 1 has serial data coming in from a GPS receiver. It measures the gap between transitions EVERY time there is a transition. I’ve limited the print commands to only occur every second so I can keep up with the data. Otherwise there’s too much to print too often and the output becomes garbled.
I’m using code like this to read serial data by interrupts. You could potentially time the gap between transitions and decide, if it’s over 20?s, what you want to do. My Arduino Duemilanove measures down to 4?s resolution.
volatile unsigned long previousTime = 0;
volatile unsigned long period = 0;
attachInterrupt(1, interrupt, CHANGE);
unsigned long currentTime = micros();
period = currentTime - previousTime;
previousTime = currentTime;