RGB Led won't compile

// put your setup code here, to run once:

//interactive adjustable RGB LED circuit

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

int potRedPin=0;
int potGreenPin = 1;
int potBluePin = 2;

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

int potRed = analogRead(potRedPin);
int potGreen = analogRead(potGreenPin);
int potBlue = analogRead(potBluePin);

int val1 = map(potRed,0,1023,0,255);
int val2 = map(potGreen,0,1023,0,255);
int val3 = map(potBlue,0,1023,0,255);
//print value of red, green & blue LED's from serial port




color RGB(val1,val2,val3);

//define the colorRGB function

void colorRGB(int red, int green, int blue){

// put your main code here, to run repeatedly:


Why won't this compile? I have gone over this sketch 50 times and cannot find what I have missed . The sketch is from DFRobot the Arduino beginners kit project 12

I get a colorRGB(val1,va2,val3)not defined Please help. Thank you

RGB Led won't compile

I'm not surprised. Only code compiles.

If you put every { on a line BY ITSELF, and every } on a line BY ITSELF, and properly indented your code, you'd see that the colorRGB() function is INSIDE the loop() function. That is NOT allowed.

Count your '{ }' pairs.

A very helpful troubleshooting tool is the Auto Format feature (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor). If you do an Auto Format and then compare the resulting indentation to your intended program structure, it will quickly point you to where there is a missing or extra brace.

Another useful feature of the Arduino IDE/Arduino Web Editor is that when you place the cursor next to one bracket, it puts a box around the matching bracket. In the Arduino IDE, if the cursor is next to the closing bracket and the opening bracket is off the screen then it will show the opening bracket line in a tool tip after a short delay.


Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

Thanks to everyone. i have my sketch working. You steered me in the right direction. My biggest hang-up was the code (sketch) given by dfRobot which has several errors. I did message them so hopefully it will be corrected.