Servo motor doesn't respond to code.

Hi ;
i’m trying to make servo motor (tiny_s) move accordingly to an angle :
here is the code :

//SERVO
#include<Servo.h>
Servo tiny_s;
int Angle=0,Position=90;

void setup() {
  tiny_s.attach(9);
  tiny_s.write(90);
}
void loop() {
        if(Angle<180 && Angle>0)
        {
           if(Position>=Angle)
           {
             while(Position!=Angle)
             {
                   Position--;
                   tiny_s.write(Position);delay(100);
             }
            }
           else if(Position<=Angle)
           {
             while(Position!=Angle)
             {
                   Position++;
                   tiny_s.write(Position);delay(100);
             }
           }
        } 

}

// so when i change the value of the angle then i send the code to arduino board the servo motor doesn’t work as it should
i’ve already verified that the servo works
Please Help ;
THANKS ;

the servo motor doesn't work as it should

What does it do ?

        if(Angle<180 && Angle>0)
        {
           if(Position>=Angle)
           {
             while(Position!=Angle)
             {
                   Position--;
                   tiny_s.write(Position);delay(100);
             }
            }
           else if(Position<=Angle)
           {
             while(Position!=Angle)
             {
                   Position++;
                   tiny_s.write(Position);delay(100);
             }
           }
        }

to

  if (Angle < 0) Angle = 0 ;
  if (Angle > 180) Angle = 180 ;   // Constraint target angle to correct range

  if (Position != Angle)   // if not at position progress it one step.
  {
    Position += Position > Angle ? -1 :+1 ;  // conditional expression, step +1 or -1 as appropriate
    tiny_s.write (Position) ;
    delay (100) ;   // this can be replaced by using BlinkWithoutDelay techniques
  }

The Arduino wiring runtime provides a function constrain() which can be used to simplify the first couple of lines to:

Angle = constrain(Angle, 0, 180);

Servo test code you can try with your servo.

// zoomkat 12-25-13 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// Send an a to attach servo or d to detach servo
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h> 
String readString; //String captured from serial port
Servo myservo;  // create servo object to control a servo 
int n; //value to write to servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("servo all-in-one test code 12-25-13"); // so I can keep track of what is loaded
  Serial.println();
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 

      // attach or detach servo if desired
    if (readString == "d") { 
      myservo.detach(); //detach servo
      Serial.println("servo detached");
      goto bailout; //jump over writing to servo
    }
    if (readString == "a") {
      myservo.attach(7); //reattach servo to pin 7
      Serial.println("servo attached");
      goto bailout;
    }    

    n = readString.toInt();  //convert readString into a number

    // auto select appropriate value
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n); 
    }

bailout: //reenter code loop
    Serial.print("Last servo command position: ");    
    Serial.println(myservo.read());
    Serial.println();
    readString=""; //empty for next input
  }
}

THanks , the probleme was solved
here is the code

#include<Servo.h>

Servo tiny ;
int pos=90 ;
char ordre ;



void setup()
{
  tiny.attach(9);
  Serial.begin(9600);
}
void loop()
{
  tiny.write(pos);
  delay(10);
  SEND();
}
  void SEND()
{
  if(Serial.available()>0)
  {ordre = Serial.read();
  if(ordre =='d' || ordre =='D')
 { pos=pos-2; }
  else if (ordre =='g' || ordre =='G')
  {pos=pos+2;}
}
}