This library is used for measuring distance with the HC-SR04, which is an ultrasonic sensor that measures distances from 2 to 400cm. My library features a temperature correction and can utilize one trigger pin with multiple echo pins in parallel. I based this library on two other libraries.
#include <HCSR04.h>
byte triggerPin = 21;
byte echoCount = 2;
byte* echoPins = new byte[echoCount] { 12, 13 };
void setup () {
Serial.begin(115200);
HCSR04.begin(triggerPin, echoPins, echoCount);
}
void loop () {
double* distances = HCSR04.measureDistanceCm();
for (int i = 0; i < echoCount; i++) {
if (i > 0) Serial.print(" | ");
Serial.print(i + 1);
Serial.print(": ");
Serial.print(distances[i]);
Serial.print(" cm");
}
Serial.println("");
delay(500);
}