Here's a collection of the bits I used in an RF remote control - push a button, create an interrupt.
//***************************************************
// * Name: pin2Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin2Interrupt()
{
g_flag = 1;
}
byte g_flag;
void setup() {
pinMode(pin2, INPUT); // our sleep interrupt pin
digitalWrite(pin2, HIGH); //enable internal pullup resistor - pin going low causes interrup
attachInterrupt(0, pin2Interrupt, LOW); // ready to be interrupted
}
void loop(){
If (g_flag == 0){
Serial.print ('L');
}
else {
detachInterrupt(0); //disable interrupts while printing
Serial.print ('G');
g_flag = 0; // reset the interrupt flag
attachInterrupt(0, pin2Interrupt, LOW); // ready for next interrupt
}
}
If you can get that working, then you will see a G on each rising edge.
Next you can change it to have the ISR be
g_flag = 1-g_flag;
and not clear g_flag with the serialprint, but hold it,
and let the state will change in the interrupt 1-0-1-0 with each edge.
Then, add stuff to capture the time when the g_flag changes.