- // C++ code
- // 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() {
- pinMode(4, OUTPUT);
- pinMode(5, OUTPUT);
- pinMode(6, OUTPUT);
- pinMode(7, OUTPUT);
- }
- void loop() {
- if (0.01723 * readUltrasonicDistance(2, 3) < 10) {
- digitalWrite(4, LOW);
- digitalWrite(5, HIGH);
- digitalWrite(6, LOW);
- digitalWrite(7, HIGH);
- } else {
- digitalWrite(4, HIGH);
- digitalWrite(5, LOW);
- digitalWrite(6, LOW);
- digitalWrite(7, HIGH);
- delay(10); // Delay a little bit to improve simulation performance
- }
- }
[text] GitHub obstacle avoidance
Viewer
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:
Latest Code Pastes