[text] GitHub obstacle avoidance

Viewer

copydownloadembedprintName: GitHub obstacle avoidance
  1. // C++ code
  2. // long readUltrasonicDistance(int triggerPin, int echoPin) {
  3. // pinMode(triggerPin, OUTPUT);
  4. // Clear the trigger
  5. // digitalWrite(triggerPin, LOW);
  6. // delayMicroseconds(2);
  7. // Sets the trigger pin to HIGH state for 10 microseconds
  8. // digitalWrite(triggerPin, HIGH);
  9. // delayMicroseconds(10);
  10. // digitalWrite(triggerPin, LOW);
  11. // pinMode(echoPin, INPUT);
  12. // Reads the echo pin, and returns the sound wave travel time in microseconds
  13. // return pulseIn(echoPin, HIGH);
  14. // }
  15. void setup() {
  16.   pinMode(4, OUTPUT);
  17.   pinMode(5, OUTPUT);
  18.   pinMode(6, OUTPUT);
  19.   pinMode(7, OUTPUT);
  20. }
  21. void loop() {
  22.   if (0.01723 * readUltrasonicDistance(2, 3) < 10) {
  23.     digitalWrite(4, LOW);
  24.     digitalWrite(5, HIGH);
  25.     digitalWrite(6, LOW);
  26.     digitalWrite(7, HIGH);
  27.   } else {
  28.     digitalWrite(4, HIGH);
  29.     digitalWrite(5, LOW);
  30.     digitalWrite(6, LOW);
  31.     digitalWrite(7, HIGH);
  32.     delay(10); // Delay a little bit to improve simulation performance
  33.   }
  34. }

Editor

You can edit this paste and save as new:


File Description
  • GitHub obstacle avoidance
  • Paste Code
  • 29 Apr-2024
  • 988 Bytes
You can Share it: