90 Degree turn using sensor

Hi team
Following code snap for rotate the robot at Left Right and Around
In this case delay is used to decide the value of angle robot to be rotated
Once we set the delay value for example 90 degree it is working fine
But due to decay of battery voltage the motor speed can be reduced So previously set angle can be changed

as a solution we can use
for example turn Left
we can rotate robot until sensor one reached the black line and then stop the rotation
Hope above solution is worked

But I don’t understand how it write properly using coding
Hi expert…Can you please help me to write it

Thanks in advanced

void turn(unsigned char dir)
{
  switch(dir)
  {
  case 'L':
    // Turn left.
    OrangutanMotors::setSpeeds(-80, 80);
    delay(200);
    break;
  case 'R':
    // Turn right.
    OrangutanMotors::setSpeeds(80, -80);
    delay(200);
    break;
  case 'B':
    // Turn around.
    OrangutanMotors::setSpeeds(80, -80);
    delay(400);
    break;
  case 'S':
    // Don't do anything!
    break;
  }
}

Hello.

It is generally beyond the scope of our direct technical support to write custom user code like that, but what you’re describing sounds similar to how our maze solving example for the Zumo shield robot handles turns. So, you might be able to use the turn() function that starts on line 173 as an example.

The Zumo shield line sensor array consists of 6 sensors, so the turn() function continues to turn until one of the sensors (the second sensor in toward the turning direction) passes over the line.

Brandon