PING problems

okay, so this is my second robot. it is supposed to be either a photovore using two photoresistors or avoid wall using a ping sensor. everthing works right, switching between modes, getting sensor input, everthing. except in the second mode(wall avoiding) where there is something wrong with writing to the servos. one is supposed to spin and the other not but both just keep spinning. the ping input is right though. here is my code:

#include <Servo.h>

Servo rightservo;
Servo leftservo;
int leftsensor;
int rightsensor;
int mode = 0;
//0 = photovore 1 = wall avoidance
const int pingPin = 7;

long microsecondsToInches(long microseconds)
  {
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
  }

  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 travelled.
  return microseconds / 29 / 2;
  }
void setup()
{
  pinMode(14,INPUT);
  pinMode(15,INPUT);
  pinMode(8,INPUT);
  pinMode(9, INPUT);
  rightservo.attach(13);
  leftservo.attach(6);
  Serial.begin(9600);
}
void loop()
{
  if(mode == 0)
  {
  Serial.println(mode);
  leftsensor = analogRead(14);
  rightsensor = analogRead(15);
  if (leftsensor > rightsensor)
  {
    leftservo.write(0);
    rightservo.write(180);
  }
  if (rightsensor > leftsensor)
  {
    rightservo.write(0);
    leftservo.write(180);
  }
  if (leftsensor == rightsensor)
  {
    leftservo.write(90);
    rightservo.write(90);
  }
  if(digitalRead(8) == HIGH)
  {
    mode = 1;
    delay(1000);
  }
  }
  if(mode == 1)
  {
    // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // 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);
  //delay(1000)
  
  
  
  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  Serial.println(inches);
  Serial.println(mode);
  
  if(inches < 15)// i think this is where the problem is
  {
    leftservo.write(0);
    rightservo.write(180);
  }
  if(digitalRead(8) == HIGH)
  {
    mode = 0;
    delay(1000);
  }
  
  delay(100);
  }
}

thanks for any help.

one is supposed to spin and the other not but both just keep spinning. the ping input is right though.

What kind of servos are they? If a servo "just keeps spinning", it is NOT a servo. A servo has a limited range of motion, typically 180 degrees or less.

If it's a modified-for-continuous-rotation servo, you should be using servo.writeMicroseconds() to set the speed and direction of the "servos".

sorry, i should have mentioned that i modified them. but yes, it is a servo, just modified for continuous rotation. thanks for the response.

but yes, it is a servo, just modified for continuous rotation

In that case, no, it is NOT a servo. It is a DC motor with gearbox, and rather imprecise speed controller (unless you've added some other feedback mechanism).