title: Arduino code for servo motor
body: <p>I have a servo motor and I want it to spin a certain amount of degrees when I press a button.
  Currently the servos spins as long as I keep the button pushed. I also need to keep the button pushed for about half a second till the servo moves or the control LED lights up.
  I want the servo to perform a spin of x degrees or x milliseconds when I push it, no matter how long you keep the button pushed, it should perform just that movement.
  This is the code I have now:</p>
  
  <pre><code>#include &lt;Servo.h&gt;
  Servo myServo;  
  
  int LED = 13;
  int BUTTON = 4;
  
  void setup()
  {
    pinMode(LED, OUTPUT);
    pinMode(BUTTON, INPUT);
    myServo.attach(9);
  }
  
  void loop()
  {
    if(digitalRead(BUTTON)==HIGH)
     {
      digitalWrite(LED, HIGH);
      myServo.writeMicroseconds(1700);  // Counter clockwise
        delay(200); 
     }
  
    else
    {  myServo.writeMicroseconds(1500);  // Stop
       delay(200); 
       digitalWrite(LED, LOW);
    }
  }
  </code></pre>