TimeAlarms with Ultrasonic sensor

I am able to use the TimerAlarms library and it works well.

I am able to determine the distance of an object using the Ultrasonic sensor.

When I use both the TimerAlarms functions and the Ultrasonic function, the CalculateEcho() function doesn't work.
The CalculateEcho() function contains the delayMicroseconds() function.

long CalculateEcho(void)
{
long distance, duration;

digitalWrite(USTrigPin, LOW);
delayMicroseconds(2);

digitalWrite(USTrigPin, HIGH);
delayMicroseconds(10);

digitalWrite(USTrigPin, LOW);
duration = pulseIn(USEchoPin, HIGH);

//Calculate the distance (in cm) based on the speed of sound.
distance = duration / 58.2;

return distance;
}

So, I added a function in the TimeAlarms library to delay by microseconds and used that.

void TimeAlarmsClass::microdelay(unsigned long microsecs)
{
unsigned long start = micros();
while( micros() - start <= microsecs)
serviceAlarms();
}

But that still doesn't work.
Appreciate your help.

Help with what? The two libraries work independently but not when merged together? Since you only posted code fragments, it’s hard tell exactly what problem you’re dealing with.

Please review the How to use this forum instructions so you know how to properly post all of your code.

Perhaps I didn't explain well.

When I call the function CalculateEcho(), the value I get back is a certain distance (e.g. 8 cm)

But when I add the function Alarm.alarmRepeat(9, 00, 0, MyAlarm); to my program and then call CalculateEcho(), it always returns a 0.