Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

C++Blocks
Code Block
languagecpp
themeConfluence
linenumberstrue
long readUltrasonicDistance(int triggerPin, int echoPin)
{
  pinMode(triggerPin, OUTPUT);  // Clear the trigger
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
 // Sets the trigger pin to HIGH state for 10 microseconds
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin, LOW);
  pinMode(echoPin, INPUT);
 // Reads the echo pin, and returns the 
 // sound wave travel time in microseconds
  return pulseIn(echoPin, HIGH);
}
 
void setup()
{
  Serial.begin(9600);
}
 
void loop()
{
  distanceCm = 0.01723 * readUltrasonicDistance(9, 8);
  // try to make sense of the above formula!
  Serial.println(distanceCm);
  delay(10);
}]] ></ac:plain-text-body></ac:structured-macro></div></td><td><div class="content-wrapper"><p><ac:image ac:width="700"><ri:attachment ri:filename="image2020-1-20_14-54-15.png" /></ac:image></p></div></td></tr></tbody></table><p><br /></p><h3>Simulation</h3><p><ac:image ac:heightwidth="400850"><ri:attachment ri:filename="image2020-1-20_14-51-24.png" /></ac:image></p><h3>Screencast</h3><p><ac:structured-macro ac:name="widget" ac:schema-version="1" ac:macro-id="b89c498f-dd23-4e9e-8d80-837b5f86cfca"><ac:parameter ac:name="url"><ri:url ri:value="http://youtube.com/watch?v=_893RyskNz0" /></ac:parameter></ac:structured-macro></p><p><br /></p>