RGB led code help?

So I'm new to the world of Arduino, and I'm trying to write a code to make an RGB led blink through the colors of the rainbow. Whenever I try to make it blink multiple colors though, it just blinks red. This is the code I'm using :

int redPin = 11;
int greenPin = 10;
int bluePin = 9;

void setup(){
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

void loop() {
  setColor(255, 0, 0);
  setColor(0, 255, 0);
  setColor(0, 0, 255);

void setColor(int red, int green, int blue) {
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);

Does anyone know why this isn't working?

Your code looks okay. Have you tested each of the LED colors using direct wiring?

Are you aware of the differences between common cathode and common anode RGB LEDs? Your code looks to be written for a common cathode device. It should work as you expect for this type of device. If you're using a common anode device, however, the value "0" is maximum brightness, not the value "255". So your code would effectively be turning off the color that you expect to turn on.