title: Servo Motor control code issues - Arduino
body: <p>Is there a simple way of modifying the following code so that I can interrupt case '0' with another input. I'm pretty sure it has something to do with millis(), but the examples I've seen seem too complicated. I'm pretty new to coding, so any help will be great! Thanks. :)</p>
  
  <pre><code>    #include &lt;Servo.h&gt; 
  
  Servo myservo;  // create servo object to control a servo 
  
  void setup() 
  { 
    myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
    Serial.begin(9600); //begins serial communication
  } 
  
  void loop() 
  { 
    int pos;
    if (Serial.available()){
      delay(100);
      while(Serial.available()&gt;0){
        pos=Serial.read();     //reads the value sent from Visual Basic  
        if(pos=='0'){
     myservo.write(45);  // Turn Servo Left to 45 degrees
     delay(1000);
     // Wait 1 second
     myservo.write(0);   // Turn Servo Left to 0 degrees
     delay(1000);          // Wait 1 second
     myservo.write(90);  // Turn Servo back to center position (90 degrees)
     delay(2000);          // Wait 2 second
     myservo.write(135); // Turn Servo Right to 135 degrees
     delay(1000);          // Wait 1 second
     myservo.write(180); // Turn Servo Right to 180 degrees
     delay(4000);          // Wait 4 second
     myservo.write(90);  // Turn Servo back to center position (90 degrees)
     delay(1000);}          // Wait 1 second
        else if(pos=='1')
          myservo.write(-90);  //rotates the servo 90 degrees (right)
        else if(pos=='2')
          myservo.write(180);  //rotates the servo 180 degrees (Left)
        else if(pos=='3')
          myservo.write(-180); //rotates the servo 180 degrees (right)     
      }
    } 
  } 
  </code></pre>