I wrote this code so my bot can approach an object, look left then right and turn toward the direction with the most space. Pretty new to code writing so im sure its not written too well. i uploaded it and all my bot does is look left then right and always turn left. Any Help please??? or any links to similar codes i can use for guidance? any help would be greatly appreciated. thanks

// The Ping is triggered by a HIGH pulse of 2 or more microseconds. // We give a short LOW pulse beforehand to ensure a clean HIGH pulse. pinMode(pingpin, OUTPUT); digitalWrite(pingpin, LOW); delayMicroseconds(2); digitalWrite(pingpin, HIGH); delayMicroseconds(5); digitalWrite(pingpin, LOW);

// The same pin is used to read the signal from the Ping: a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(pingpin, INPUT); duration = pulseIn(pingpin, HIGH);

// Convert the time into a distance. cm = microsecondsToCentimeters(duration); return(cm);}

long microsecondsToCentimeters(long microseconds){ // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance traveled. return microseconds / 29 / 2;}