Skip to content

Instantly share code, notes, and snippets.

@blister
Last active January 20, 2019 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blister/3144a495d3c3190f4c8c1cb31a58ef25 to your computer and use it in GitHub Desktop.
Save blister/3144a495d3c3190f4c8c1cb31a58ef25 to your computer and use it in GitHub Desktop.
long ping() {
long duration;
// clear ping pin
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
duration = pulseIn(echoPin, HIGH);
return duration;
}
// Helper function to return the distance to an object
// detected by the ultrasonic sensor in centimeters.
long msToCm(long microseconds) {
return microseconds * .034 / 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment