Go to the documentation of this file.00001
00002
00003 float microsecondsToCm(long microseconds)
00004 {
00005
00006
00007
00008 return microseconds / 29 / 2;
00009 }
00010
00011 long Ping(int pin) {
00012 long duration, range;
00013
00014
00015
00016 pinMode(pin, OUTPUT);
00017 digitalWrite(pin, LOW);
00018 delayMicroseconds(2);
00019 digitalWrite(pin, HIGH);
00020 delayMicroseconds(5);
00021 digitalWrite(pin, LOW);
00022
00023
00024
00025
00026 pinMode(pin, INPUT);
00027 duration = pulseIn(pin, HIGH);
00028
00029
00030 range = microsecondsToCm(duration);
00031
00032 return(range);
00033 }
00034