HC-SR04 Can I use a delay within a SimpleTimer function?

Hi,
You might think that there’s a lot of these types of questions, but I couldn’t find any answer of mine. Basically, I want to use a HC-SR04 Ultrasonic sensor. I know that I should use a SimpleTimer instead of doing the ultrasonic stuff inside the loop function. Right now I have this:

void Ultra()
{
   digitalWrite(UltraTrig, LOW);  
   delayMicroseconds(2); 
  
   digitalWrite(UltraTrig, HIGH);
   delayMicroseconds(10); 

   digitalWrite(UltraTrig, LOW);
   duration = pulseIn(UltraEcho, HIGH);
   distance = (duration/2) / 29.1;

   if (distance <= UltraDist) {
  StatusLED.setColor("#23C48E");
  DoorState = 1;
   }
   else {
    StatusLED.setColor("#D3435C");
    DoorState = 0;
   }

}

void setup() {

timer.setInterval(1000L, Ultra);

}

void loop
{
  Blynk.run();
  timer.run();
}

//It’s not the whole code it’s just a part of it

Is it ok to use the delay (or delayMicroseconds) within the Ultra function or should I do a separate function that will trigger those things with SimpleTimer?

10 Microseconds delay is fine.

Thanks

This code it’s working? I’m interest :slight_smile: