RGB LED Colour Look-up Array Problems

I wrote some code to set and RGB LED certain colours. I have made a 2D array of colours. But i had to put it in the setColours() function that i made because it didn't work outside of it.

How do i get array to work in custom functions? And is there a better way to have a colour look-up?

int R;
int G;
int B;

void setup() {
  setPins(9, 10, 11);
}

void loop() {
  for (int k = 0; k < 16; k++) {
    setColour(k);
    delay(500);
  }
}

void setPins(int R, int G, int B) {
  pinMode(R, OUTPUT);
  analogWrite(R, 0);
  pinMode(G, OUTPUT);
  analogWrite(G, 0);
  pinMode(B, OUTPUT);
  analogWrite(B, 0);
}

void setRGB(int Rval, int Gval, int Bval) {
  analogWrite(R, Rval);
  analogWrite(G, Gval);
  analogWrite(B, Bval);
}

void setColour(int i) {
  int COLOURS[16][3] = {
  {255,0,0},
  {0,255,0},
  {0,0,255},
  {255,255,0},
  {0,255,255},
  {255,0,255},
  {255,255,128},
  {128,255,255},
  {255,128,255},
  {255,128,0},
  {128,255,0},
  {128,0,255},
  {128,128,0},
  {128,0,128},
  {0,128,128},
  {128,64,0}
};
  analogWrite(R, COLOURS[i][0]);
  analogWrite(G, COLOURS[i][1]);
  analogWrite(B, COLOURS[i][2]);
}

[edit]You have to use a number to lookup the colour from the array, because I couldn't work out how to get it to lookup from an array using colour names e.g. BLUE = 3 or something. That is without bulky ifs and stuff...[/edit]

You could use #define statements to associate color names with numbers.

Ok, so i've got this:

int R;
int G;
int B;
int y;
#define RED 1;
#define GREEN 2;
#define BLUE 3;
#define YELLOW 4;
#define TURQUOISE 5;
#define PINK 6;
#define LIGHTYELLOW 7;
#define LIGHTBLUE 8;
#define ROSE 9;
#define ORANGE 10;
#define LIME 11;
#define VIOLET 12;
#define DRITYYELLOW 13;
#define PLUM 14;
#define TEAL 15;
#define BROWN 16;

void setup() {
setPins(9, 10, 11);
// Serial.begin(19200);
}

void loop() {
setColour(BROWN);
}

void setPins(int R, int G, int B) {
pinMode(R, OUTPUT);
analogWrite(R, 0);
pinMode(G, OUTPUT);
analogWrite(G, 0);
pinMode(B, OUTPUT);
analogWrite(B, 0);
}

void setRGB(int Rval, int Gval, int Bval) {
analogWrite(R, Rval);
analogWrite(G, Gval);
analogWrite(B, Bval);
}

When i use a number to get a colour, it works fine. But when I use a defined word e.g. TEAL, there is an error saying:

In function 'void loop()':
error: expected `)' before ';' token

Which doesn't make sense to me? What is wrong here?

Cheers, Ben

In your #define lines, remove the trailing semicolons.
Semicolons are statement terminators in C, #define's are
not C per-se -- just commands for the C preprocessor.

Why not call setRGB() from within your setColour() function?
That way, if you change the way you setup your colours, you
don't have to change setColour() as well.

Oh, one more thing -- try not use local variables with the same
names as globals (eg R, G, & B). This is more a style thing but
it can lead to some confusion as to which variables you want the
program to actually use.

I made it wothout the semicolons originally, but it didn't work. So i shoved them in and it did, kinda...

But it's fine now, Thanks!

Ben