Library for save timestamp on pin change - for ultrasonic or buttons.
pcAttachPin(#);pcDetachPin(#)
while(isPcEvent()) {
if (pcEventPin() == ECHO) { // Edge
if (pcEventRiseEdge())
starttime=pcEventStamp();
else
timeToEcho = ticksToMicros(pcEventStamp() - starttime);
} else if (pcEventPin() == ....
....
pcEventPop();
}