Problem with connecting two pieces of code

I'm having trouble with this project. The first piece of code has an RGB LED that is connected to a button. When you hold down the button you get a red light and then a yellow light then a green light then off and it loops. If you let go of the button it immediately shuts off. I have another piece of code which allows the same RGB LED to be connected to the Serial Monitor. The LED responds based on different numbers that you put in to the Serial Monitor. Both pieces of code work individually, however when I put them together I can't get them both to work. Only one the code with the button does. Does anyone have an idea why it's not working?

Here is my first code:

char N;
int buttonPin=4;
int greenPin=9;
int bluePin=10;
int redPin=11;

void setup()
{
Serial.begin(9600);
pinMode(buttonPin,INPUT_PULLUP);
}

void loop()
{
while(digitalRead(buttonPin)==1)
{
analogWrite(redPin,0);
analogWrite(greenPin,0);
analogWrite(bluePin,0);
}
while(digitalRead(buttonPin)==0)
{
if(digitalRead(buttonPin)==0)
{
analogWrite(redPin,255);
delay(1000);
}
else
{
analogWrite(redPin,0);
analogWrite(greenPin,0);
analogWrite(bluePin,0);
}
if(digitalRead(buttonPin)==0){
analogWrite(redPin,245);
analogWrite(greenPin,255);
analogWrite(bluePin,0);
delay(1000);
}
else
{
analogWrite(redPin,0);
analogWrite(greenPin,0);
analogWrite(bluePin,0);
}
if(digitalRead(buttonPin)==0)
{
analogWrite(redPin,0);
analogWrite(bluePin,0);
analogWrite(greenPin,225);
delay(1000);
analogWrite(greenPin,255);
}
else
{
analogWrite(redPin,0);
analogWrite(greenPin,0);
analogWrite(bluePin,0);
}
if(digitalRead(buttonPin)==0)
{
analogWrite(redPin,0);
analogWrite(bluePin,0);
analogWrite(greenPin,0);
delay(100);
}
else
{
analogWrite(redPin,0);
analogWrite(greenPin,0);
analogWrite(bluePin,0);
}
}
while(digitalRead(buttonPin)==1);
while(digitalRead(buttonPin)==0);
}

Here is my second code:

int N;
int greenLED=9;
int blueLED=10;
int redLED=11;
void setup(){
Serial.begin(9600);
}
void loop(){
if(Serial.available()>0){
N=(Serial.read());
switch(N)
{
case '1':
analogWrite(redLED,255);
analogWrite(greenLED,0);
analogWrite(blueLED,0);
break;
case '2':
analogWrite(redLED,0);
analogWrite(greenLED,255);
analogWrite(blueLED,0);
break;
case '3':
analogWrite(redLED,0);
analogWrite(greenLED,0);
analogWrite(blueLED,255);
break;
case '4':
analogWrite(redLED,0);
analogWrite(greenLED,0);
analogWrite(blueLED,0);
analogWrite(greenLED,200);
analogWrite(redLED,175);
analogWrite(blueLED,210);
break;
case '5':
analogWrite(redLED,0);
analogWrite(greenLED,0);
analogWrite(blueLED,0);
break;
}
}
}

Thanks for your help.

Does anyone have an idea why it's not working?

As you didn't post the combined code it is impossible to say. When/if you do post it please put code tags (the </> icon) round it to make it easier to read and copy.

while(digitalRead(buttonPin)==0)
{ 
  if(digitalRead(buttonPin)==0)

{cough}