   if (safetyDriveMode) {
     int checkDistanceInterval = map(
       motorSpeed,
-      0, 255,
+      0, maxMotorSpeed,
       500, 0
     );
     
     int distanceToStop = map(
       motorSpeed,
-      0, 255,
+      0, maxMotorSpeed,
       15, 50
     );
     

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

int motorSpeed = 100;
bool isMovingForward = false;
bool isMovingBackward = false;
bool safetyDriveMode = true;

{
  int currentMotorSpeedInPercentage = map(
    motorSpeed,
    0, maxMotorSpeed,
    0, 100
  );
  
