RGB led PWM problems with values less than 255 [SOLVED]

I am creating a controller to drive 10 meters of RGB LED's. It's essentially an Arduino Pro Mini connected to three mosfets and an IR receiver on a circuit board. The hardware doesn't really matter as I've confirmed it working with basic scripts such as a hue cycle I wrote.

Where my problem lies is in my main controller code. The code is supposed to read the IR code from the remote using a library and then it uses a switch case to change colors. The basic functionality works, but I have started to implement brightness control and this is where I am having issues.

The code uses map to change the overall brightness of the color outputs. For the red and blue LED's the brightness works as expected, but for the green LED's if the PWM value is anything less than 255 then they turn off completely. I have confirmed via serial that the values are what they should be. What is confusing is that if I change the pin numbers in the program so that outputting red is actually on the green pin, the result is the same. Even if I analogWrite a value of 250 in void setup() the result is identical to the original issue. I have uploaded some of my test codes again and they work flawlessly with the green channel fading/outputting below 255. Can any of you spot my mistake or offer any advice? The code is a little rough since it is a work in progress and there are is still more functionality I plan to add. Thanks!

//Include Libraries
#include <IRremote.h>

//Various variables
long ir = 0;
int RECV_PIN = 11;
int lastir = 0;
int brightness = 255;

int red = 5;
int green = 3;
int blue = 9;

//Prepare IR Library
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  
  //Set all outputs to 0
  analogWrite(red,0);
  analogWrite(green,0);
  analogWrite(blue,0);
}

void loop() {
  //Get IR code from reciever
  if (irrecv.decode(&results)) {
    lastir = ir;
    ir = results.value;
    Serial.println(ir); //Print to serial for debugging
    irrecv.resume(); // Receive the next value
  }
  //Start switch case
  switch(ir){
    case 284103405: //Power Button
      power();
      break;
    
    case 284151855: //Brightness up
      changeBrightness(1);
      break;
    
    case 284111055: //Brightness down
      changeBrightness(0);
      break;
    
    
    //Color Buttons follow
    case 284147775: //White
      color(255,255,255);
      break;
    
    case 284131965: //red
      color(255,0,0);
      break;
    
    case 284131455: //green
      color(0,255,0);
      break;
      
    case 284115135: //blue
      color(0,0,255);
      break;
  }
}

void reset(){ //resets all colors to 0 when called
  analogWrite(red, 0);
  analogWrite(green, 0);
  analogWrite(blue, 0);
}

void power(){
  reset();
}

void changeBrightness(int x){ //modifies brightness value
  if(x==1){ //up
    brightness = brightness+5;
    brightness = constrain(brightness,0,255);
  }
  if(x==0){ //down
    brightness = brightness-5;
    brightness = constrain(brightness,0,255);
  }
  //diagnostics
  Serial.print("Brightness: ");
  Serial.println(brightness);
}


void color(int r, int g, int b){
  reset();
  //apply brightness by mapping the value
  r = map(r,0,255,0,brightness);
  g = map(g,0,255,0,brightness);
  b = map(b,0,255,0,brightness);
  //write the values
  analogWrite(red, r);
  analogWrite(green, g);
  analogWrite(blue, b);
  //diagnostics
  Serial.println(r);
  Serial.println(g);
  Serial.println(b);
}
void color(int r, int g, int b){
  reset();
  //apply brightness by mapping the value
  r = map(r,0,255,0,brightness);
  g = map(g,0,255,0,brightness);
  b = map(b,0,255,0,brightness);
  //write the values
  analogWrite(red, r);
  analogWrite(green, g);
  analogWrite(blue, b);

Why is it necessary to set all the pins to 0 first?

If writing a value less than 255 to one of the pins results in the lights associated with that pin going odd, that sounds like a hardware problem, not a software problem.

PaulS:
Why is it necessary to set all the pins to 0 first?

If writing a value less than 255 to one of the pins results in the lights associated with that pin going odd, that sounds like a hardware problem, not a software problem.

I set them all to zero while I was testing and never turned it back. It does the same thing either way.

I originally thought it would be hardware, but I just threw together some code together that works like it should. It sets the green pin to a value less than 255 and the result is correct. I can set it to any number below 255 and it works aswell.

void setup(){
  analogWrite(3,100);
  analogWrite(5,0);
  analogWrite(9,0);
}

void loop(){
}

All analog write commands must be 255 or less. If they are greater then the number just wraps round. That is 256 is exactly the same as 1.

See what value you have in your code by printing out the values with a serial print.

New post while I was writing, I'll merge them:

Thanks for the suggestion Grumpy_Mike. I had already tried looking at the values through serial and they were as desired and in between 0 and 255 so that wasn't the issue.

I managed to solve my own problem. I was (too conveniently) passing time by reading about advanced PWM and timers. I thought that maybe the IR library I am using somehow messes with timer2 which is pins 3 and 11. Green happens to be on pin 3. I confirmed this by placing the IR portion of the code into one of my simple scripts where it failed to work. So I shuffled my pins around so that the outputs were on 5, 6, and 9 which is only timer0 and timer1. This solved the issue and I can now PWM properly on all the pins!