title: Arduino sketch with Serial.available() passes twice
body: <p>When I test <code>Serial.available()</code> or <code>Serial.available() &gt; 0</code> in my <code>loop()</code> function, it appears to return <code>true</code> <em>twice</em> each time I enter serial data. The second time, it sets the <code>throttle</code> value in my code to <code>0</code>. Here is the code:</p>
  
  <pre><code>#include &lt;Servo.h&gt;
  
  Servo rc_rotor;
  
  int throttle = 0; // servo position indicates throttle position.
  
  String s_throttle_set = "Throttle set to: ";
  String s_throttle_read = "Reading throttle value: ";
  String s_action_error = "No action known for input value: ";
  
  void setup() 
  {
    rc_rotor.attach(9);
    Serial.begin(9600);
    while(! Serial);
    Serial.println("Throttle value: 0 through 255, or 999 to read current value.");
  }
  
  void loop() 
  {
    rc_rotor.write(throttle);
    delay(20);
    if (Serial.available()) 
    { 
      int temp_throttle = Serial.parseInt();
  
      if (temp_throttle &gt;= 0 &amp;&amp; temp_throttle &lt;= 180)
      {
        throttle = temp_throttle;
        Serial.println(s_throttle_set + throttle);
      } 
      else if (temp_throttle == 999) 
      {
        Serial.println(s_throttle_read + throttle);
      } 
      else 
      {
        Serial.println(s_action_error + temp_throttle);
      }
    }
  }
  </code></pre>
  
  <p>Please note this code is not my final masterpiece. Much of it is from publicly available examples. Anyway, the statement <code>if (Serial.available())</code> succeeds twice. By that I mean, it is <code>true</code> when I type in a value such as <code>125</code>, and a moment later it will be 'true' again when I have typed in nothing additional. I only expect one value to go through this way. The result is that my <code>throttle</code> is being set to the value I enter, and then almost immediately re-set to <code>0</code>. Why would something like this happen?</p>