Problem with sketch on Mega2560 PLEASE HELP!

Hi all. I'm using a sketch

int Red, Green, Blue;

int RedPin = 10;
int GreenPin = 9;
int BluePin = 11;


void setup()
{
  Serial.begin(19200);
  Red = 0;
  Green = 0;
  Blue = 0;
}

void loop()
{
  if (Serial.available()>=3) {
    if(Serial.read() == 0xff){
      Red = Serial.read();
      Green = Serial.read();
      Blue = Serial.read();
    
      analogWrite (RedPin, Red);
      analogWrite (GreenPin, Green);
      analogWrite (BluePin, Blue);
    }
  }
}

I don't have any trouble running the code on Arduino Nano, Duemilanove, Uno R3, Pro mini everything works i have the exact output on the pin's selected I have even uploaded it to a atmega32 and it works but when i upload it to the mega, i don't get any output on the pins selected does not matter which pin's i select in the code there isn't anything please advice.

Where is the incomming serial data comming from ?

i.e from the PC or have you connected to the pins on the board because on ATMega32U4 boards the pins i.e 0 and 1 on the board are Serial1 not Serial

Apart from that, have you tried setting pinmode to output on the pins you want to use as outputs (though I doubt this is the problem)

hi i get the data from a program writen on java i do set the com port in java but the problem persist i will try with pin mode and write back

you are checking for available >= 3

and you read either 4 times or 1 time from serial so there is some thing wrong

try

void loop()
{
  if (Serial.available() >= 4) // <<<<<<<<<<
  {
    if (Serial.read() == 0xff)
    {
      Red = Serial.read();
      Green = Serial.read();
      Blue = Serial.read();
      analogWrite (RedPin, Red);
      analogWrite (GreenPin, Green);
      analogWrite (BluePin, Blue);
    }
  }
}

in the line
if (Serial.available() >= 4) // <<<<<<<<<<
i've tried with everything from 0 to 14.