Servo Control Problem

Hi, I need help for my Servo control. I use a EWTS86 sensor to
measure the angle of my head movement, then I use the following code to capture the signals from sensor in order to control the Servo turning angles.
The problem is that when everytime my movement stops, the sensor's signal will be set to 512(analog value), after map() functions, it means 90 degree. so the Servo turns to the 90 degree position. but actually what I need is that when I stop moving, the Servo should also stops too instead of going back to the 90 degree position.
Need your help.

int servopin = 13;
int readValue =0;// Serial.read();
int value = 0;
int sensor = 0;
void setup()
{
pinMode(servopin, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
Serial.available();

}
void loop()
{
value = analogRead(sensor);

//Serial.println(value);
value = map(value, 0, 1023, 0, 179);

servopulse(value);

for(int i=0;i<50;i++)
{
servopulse(readValue);
}

}
void servopulse(int angle)
{
int pulsewidth=(angle*11)+500;
digitalWrite(servopin,HIGH);
delayMicroseconds(pulsewidth);
digitalWrite(servopin,LOW);
}

Does the sensor signal go back to 512 at once? If so, you could ignore the 512 value and keep the servo at the value it had before it went to 512.

Does that make sense?

If value = 512 means the gyro is no longer moving, do lower values mean it is moving one way, and higher values mean it is moving the other way?

If so, then sending the servo to the measured value is probably not the best approach.

Instead, you should keep track of where the servo is, and where your head is, and move the servo an amount proportional to the relative change in sensor value (head position).

I don't understand what this code is doing:

void loop()  
{  
 value = analogRead(sensor);

 //Serial.println(value);
 value = map(value, 0, 1023, 0, 179);
 
 servopulse(value);

  for(int i=0;i<50;i++)  
  {  
       servopulse(readValue);  
  }  
 
}

The first part, where the sensor value is read, and mapped, and sent to the servo I understand. It's the for loop that sends 0 to the servo 50 times that I don't get.

sensor signal does not go back to 512 at once