Last active
January 20, 2019 23:28
-
-
Save blister/3144a495d3c3190f4c8c1cb31a58ef25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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