arduino and processing serial problem

i have a problem with arduino and processing serial. when i loaded the code for arduino in the mega board, the servo was set to 90 degrees and this worked fine. However, then i ran processing code, the rx led flashed which looked right but the servo wont work as it supposed to.

arduino code:

#include <Servo.h>

Servo servo;
int pos=90;

void setup()
{
  servo.attach(8);
  servo.write(90);
  Serial.begin (9600);
}

void loop()
{
  if (Serial.available()>0)
  {
    byte input = Serial.read();
    if (input == 'L')
    {
      servo.write (pos--);
    }
    else if (input == 'R')
    {
      servo.write(pos++);
    }
  }
}

processing code:

import processing.serial.*;
Serial port;

void setup()
{
  size(50,50);
  port = new Serial (this, "COM3",9600);
  delay(300);
}

void draw()
{
  if (keyPressed) 
  {
    if (key == CODED)
    {
      if (keyCode == LEFT && keyCode != RIGHT)
      {
        port.write ('L');
        println("L");
        delay(30);
      }
      if (keyCode == RIGHT && keyCode != LEFT)
      {
        port.write('R');
        println("R");
        delay(30);
      }
    }
  }
  else
  {
    port.write('c');
    println("c");
    delay(30);
  }
}

all of these work fine if i use firmata. But i want to use PID controller library in arduino. thats why i chose to do it this way

I connected a servo to pin 8 of my Uno and loaded the Arduino code without changes. I modified the Processing code as shown (If the key is LEFT it can't be RIGHT so why check?). Works fine as far as I can see. The servo moves right or left by the PC arrow key pressed. You mention PID. What is PID going to be used for?

void draw()
{
  if (keyPressed)
  {
    if (key == CODED)
    {
      if (keyCode == LEFT)
      {
        port.write ('L');
        println("L");
        delay(30);
      }
      if (keyCode == RIGHT)
      {
        port.write('R');
        println("R");
        delay(30);
      }
    }
  }