I think this is the kind of thing you need:
char* colours[7] = { // Seven colours, 0-6
"255, 255, 255", // white
"255, 0, 255", // purple
"0, 0, 255", // blue
"255, 255, 0", // green
"0, 255, 0", // yellow
"255, 153, 0", // orange
"255, 0, 0"}; // red
int randomVal;
void setup(){
}
void loop(){
}
void chooseColour() {
randomVal = random(0, 6); // Choose a random value, 0-6
switch(randomVal) {
case 0:
white();
case 1:
purple();
case 2:
blue();
case 3:
green();
case 4:
yellow();
case 5:
orange();
case 6:
red();
}
}
void white(){
}
void purple(){
}
void blue(){
}
void green(){
}
void yellow(){
}
void red(){
}
void orange(){
}
Edit -
byte colours[7][3] = { // Seven colours, 0-6
255, 255, 255, // white
255, 0, 255, // purple
0, 0, 255, // blue
255, 255, 0, // green
0, 255, 0, // yellow
255, 153, 0, // orange
255, 0, 0}; // red
int randomVal;
void setup(){
}
void loop(){
}
void chooseColour() {
int randomVal = random(0, 6); // Choose a random value, 0-6
byte redComponent = colours[randomVal][0];
byte greenComponent = colours[randomVal][1];
byte blueComponent = colours[randomVal][2];
analogWrite(redPin, redComponent);
analogWrite(greenPin, greenComponent);
analogWrite(bluePin, blueComponent);
}
It has an array of the Colour values. It then chooses a random value using the random() function. Then it uses a switch:case function to choose which colour function to go to with the selected case.
I think the reason you had difficulty with the #define statements was because you tried to use them the wrong way round. They just let the compiler replace the words e.g WHITE that you use in the code with the value attached to that statement.
Try adding this to your code (with all the additional stuff of course) and it should do what what you want.
The edited code courtesy of halley!
PS. This has been a learning curve for me too.
/me