Pots not outputting correctly

So I have just started my first real project and have run into a small snag. After running some test builds on 123D Circuits, I finally got my wiring done, and code built. On the website it works like a charm, so I thought putting it onto the real thing would be simple, I was wrong. Once I wired everything up and uploaded the code I noticed that my pots were not controlling the RGB LED like they did in the 123D. All of my Pots work, as do the wires (I moved them around just to check). So I tried a Serial Print, and saw that the only one that would read was my Red Pot, up to a point. Once the Red was high enough the Green Pot would start to bleed in when I turn it on, but would not work alone and had to have the Red almost full to get anything from it.

Here is my code. I'm not sure if it is something wrong in it that is causing the issue, or if it is something else on the breadboard/Arduino.

//RGB Potentiometers
const int reddile = A0;
const int gredile = A1;
const int bludile = A2;

//Randome color gen button
const int rando = 2;

//RGB LED
const int red = 3;
const int gre = 5;
const int blu = 6;

//Togle switch between ran button and Pot
const int diletorando = 4;

int buttonState = 0;
long randNumber;




void setup()
{
        Serial.begin(9600);
	pinMode(reddile, INPUT);
	pinMode(gredile, INPUT);
	pinMode(bludile, INPUT);
	pinMode(rando, INPUT);
	pinMode(red, OUTPUT);
	pinMode(gre, OUTPUT);
	pinMode(blu, OUTPUT);
	pinMode(11, OUTPUT);
        
	
}

void loop()
{
	
	//Switch from Pots to random number
	if (digitalRead(diletorando) == LOW)
	{
  
  buttonState = digitalRead(rando);

  
  	if (buttonState == LOW)
  {     
       //While button is pressed make first random number for the RGBs
    digitalWrite(red, LOW);       
    digitalWrite(gre, LOW);       
    digitalWrite(blu, LOW);
  }
  	else 
  {
    	//After release generate a second random number for the RGBs
    digitalWrite(red, randNumber = random(255));       
    digitalWrite(gre, randNumber = random(255));       
    digitalWrite(blu, randNumber = random(255));
  }

	}
	else
	{
	//Pots to RGB signals
	int redread = analogRead(reddile);
	int greread = analogRead(gredile);
	int bluread = analogRead(bludile);

	int mapred = map(redread,0,1023,255,0);
	int mapgre = map(greread,0,1023,255,0);
	int mapblu = map(bluread,0,1023,255,0);

	analogWrite(red, mapred);       
	analogWrite(gre, mapgre);	
        analogWrite(blu, mapblu);
       
        Serial.println(redread);        
        Serial.println(greread);        
        Serial.println(bluread);
        

}
}

So it's your first post but did you read

How to use this forum

Please put your code in its own window as seen in other posts. This can be done by placing     [code]  and [/code]  around the code or use the </> icon. This makes it easier for others to read.

You can edit the post to do this.

Weedpharma

   int mapred = map(redread,0,1023,255,0);
   int mapgre = map(greread,0,1023,255,0);
   int mapblu = map(bluread,0,1023,255,0);

The parameters for map are wrong. Please check in the documentation.

I had to reverse them because the LED I have is using a common anode, which makes me have to put the power out on pin 11 and stem the 3, 5, and 6 closer to GND.

I don' think it works that way. You are generating negative numbers for the Pam setting, which makes no sense.

The Red LED works with no problem using the code that way. I am able to dial though all of the brightness on only the Red. However the issue is with the other 2 colors, to where only the Green turns on once the Red is half though its power, and the Blue wont turn on at all. Something I was wondering is would something like a "Delay" be needed in this code at all?

No delays required. Please try and change the mapping, even if it is just to prove me wrong.

After doing that, instead of the LEDs not coming on, they would not go off. It is leading me to think there might be a short on my breadboard or between some of my wires.

"the LED I have is using a common anode,"

Then the device you have, contains three LEDs.

Do you have the anode connected directly to the 5v rail ?

Do you have three resistors connected to three IO pins? What value resistors?

So it turned out to be a short somewhere on the breadboard, I do not know exactly where at, however it works now. There does seem to be a lot of noise on the port writing to the LED, it fluctuates about 10 power. If I do a serial read on my pots it has a stable output, but if I do a read on my pins leading to the LED I can see it jump around and not output cleanly.

And to answer your question Jack. The anode is connected to pin 11 which is set to HIGH, so that I can turn the lights off or on with a mic later down the road. And the only resister I have is running to the anode. From what I found online that is the only location on a common anode LED that needs one, and it is a 220 Ohm.

"And to answer your question Jack. The anode is connected to pin 11 which is set to HIGH, so that I can turn the lights off or on with a mic later down the road. And the only resister I have is running to the anode. From what I found online that is the only location on a common anode LED that needs one, and it is a 220 Ohm."

That may seem to work (sorta), but you should have the anode connected to the 5v rail, and each of the 3 led's connected through 3, 220 ohm resisters, to the three output pins.

You can easily turn off all three leds by the three output pins.

Normally the red led will be brighter (looking) than the others, so if you want to have better proportioning light, add about 50-100 ohms on the red led.