int Servopin=5;
int angle=0;
void setup() {                
  // initialize the digital pin as an output.
  pinMode(Servopin,OUTPUT); 
}
void loop() {
  if (Serial.available() > 0) 
  { angle = Serial.read();
     if(angle>180)
     { angle=180;}
     else if(angle<0)
      { angle=0;}  
   }  
    int angle=Position*(180/9);//Calculate the angle should be moved based on the key pushed on the Remote Controller.
    for(int i=0;i<=5;i++) 
    {
    moveangle(Servopin,angle);//move the shaft to an angle based on the key pushed on the Remote Controller
    } 
}
 void moveangle(int Servopin,int angle)//the pulsewidth function,move the shaft to an angle based on the KEY pushed.
{
int pulsewidth=(angle*11)+500;//change the angle to 500-2480us pulsewidth
digitalWrite(Servopin,HIGH);
delayMicroseconds(pulsewidth);
digitalWrite(Servopin,LOW);
delay(20-pulsewidth/1000);
}
