exit status 1 'setColor' was not declared in this scope

Greetings Forum.

My project consist of changing led color (RGB) based on the position of a rotary switch (6 position). The legs of the switch are connected to an Arduino UNO and the internal PULLUP resistors are enabled for each input. The project is mobile so I will be using a 7ah battery for power.

i have been trying to understand the error so that I can use it as a building-block to further my project, but am not having a whole lot of luck finding an answer (Google) that fits my current level of program understanding. I got the bulk of the program from Adafruit and have been modifying to fit my project.

A little frustrating/confusing for me is that before I added lines 44 through 47 to my sketch, the code did not have any compiling issues so I removed lines 44 - 47 thinking all would be good if I just went back to what i had before the errors…no such luck.



if (rotPos1 == LOW);{

All of your if and else if statements end with a semicolon. Bad, bad. The semicolon ends the if or if else statement so the following line(s) will be executed unconditionally. I remove all of the semicolons at the ends or the if and if else statements and the code compiles.

Are you sure that the code that you improperly posted is the same that generated the scope error cause I don't see it.

Read the how to use this forum sticky to see how to post code. Attaching code like you did limits the number of people who will see it.

Here is your corrected code formatted in a more readable style. Note that each { and } are on their own lines. That makes the code blocks stand out and makes it easy to see in there are mismatched brackets. And the semicolons stand right out when they were there.

int rotPos1 = 2;
int rotPos2 = 4;
int relay1 = 5;
int button1 = 6;
int rotPos3 = 7;
int rotPos4 = 8;
int redPin = 9;    //RGB Red pmw
int greenPin = 10; //RGB green pmw
int bluePin = 11;  //RGB blue pmw
int rotPos5 = 12;
int rotPos6 = 13;

void setup()
   pinMode(rotPos1, INPUT_PULLUP);
   pinMode(rotPos2, INPUT_PULLUP);
   pinMode(rotPos3, INPUT_PULLUP);
   pinMode(rotPos4, INPUT_PULLUP);
   pinMode(rotPos5, INPUT_PULLUP);
   pinMode(rotPos6, INPUT_PULLUP);
   pinMode(redPin, OUTPUT);
   pinMode(greenPin, OUTPUT);
   pinMode(bluePin, OUTPUT);


void loop()
   if (rotPos1 == LOW)
      setColor(0, 0, 0);
   }  // off
   if (rotPos2 == LOW)
      setColor(255, 255, 255);
   }  // white
   else if (rotPos3 == LOW)
      setColor(0, 255, 255);
   }  // aqua
   else if (rotPos4 == LOW)
      setColor(0, 0, 255);
   } // blue
   else if (rotPos5 == LOW)
      setColor(0, 255, 0);
   } // green

void setColor(int red, int green, int blue)
   red = 255 - red;
   green = 255 - green;
   blue = 255 - blue;
   analogWrite(redPin, red);
   analogWrite(greenPin, green);
   analogWrite(bluePin, blue);