int left(int d0, int d1)
{
int cm;
long duration;
float percentage;
digitalWrite(TRIGPINL, LOW);
delay(2);
digitalWrite(TRIGPINL, HIGH);
delay(5);
digitalWrite(TRIGPINL, LOW);
duration = pulseIn(ECHOPINL, HIGH);
cm = microsecondsToCentimeters(duration);
percentage = map(cm, d0, d1, 0, 100);
return( (float)percentage / 100);
}
You know that variables can have meaningful names, right? What do d0 and d1 mean?
Since percentage IS a float, why do you need to cast it to a float?
Why IS percentage a float? The map() function does not return a float.
There is no reason to use floats at all, since the function is going to truncate the value to an integer anyway.
How do left() and right() differ? Only in the pin numbers that they use. Create ONE function that is passed the pin number(s) to use. Half as much code to debug that way.
float perl, perr;
perl = left(20, 6);
perr = right(6, 20);
So, you have a function that returns an int. You store that value in a float. Why?
You are using a lot of global variables in just one function. Knock that off. Learn about scope and how to minimize it. Learn about static variables where you want a variable to retain its value between calls to the function.
Learn to match function return values to variables used to hold the return value. Make up your mind whether you need percentage or something else. You seem to be converting from percentage to ratio and back uselessly.