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.