that_one_nigga_you_k

seliga no ping

Dec 6th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. unsigned long ping()
  2. {
  3.   pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output
  4.   digitalWrite(ultraSoundSignal, LOW); // Send low pulse
  5.   delayMicroseconds(2); // Wait for 2 microseconds
  6.   digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
  7.   delayMicroseconds(5); // Wait for 5 microseconds
  8.   digitalWrite(ultraSoundSignal, LOW); // Holdoff
  9.   pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
  10.   digitalWrite(ultraSoundSignal, HIGH); // Turn on pullup resistor
  11.   // please note that pulseIn has a 1sec timeout, which may
  12.   // not be desirable. Depending on your sensor specs, you
  13.   // can likely bound the time like this -- marcmerlin
  14.   // echo = pulseIn(ultraSoundSignal, HIGH, 38000)
  15.   echo = pulseIn(ultraSoundSignal, HIGH); //Listen for echo
  16.   ultrasoundValue = (echo / 58.138) ; //convert to CM then to centi-o-meters
  17.   return ultrasoundValue;
  18. }
Add Comment
Please, Sign In to add comment