Easiest way might be to start a timer running and use a pin change interrupt.
On the interrupt, read the time from the timer.
If the pin is high, it's a rising edge, save the time in a volatile variable.
If the pin is low, it's a falling edge, subtract the time you saved from the current time and there you have it.
The largest known prime number: 282589933-1
It's easy to stop breaking the 10th commandment! Break the 8th instead.
© 2018 Microchip Technology Inc.