Hello! For some reason even though I can dim my blue and green LED pins, the red pin won't dim (it either is completely off or maximum brightness).
I'm using a clear anode RGB LED (link: LED - RGB Clear Common Anode - COM-10820 - SparkFun Electronics and below is an image of how I've set up my board:
Here's my code:
int redPin = 12;
int greenPin = 11;
int bluePin = 10;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
setColor(100, 0, 0); // Red
delay (1000);
setColor(0, 100, 0); // Green
delay (1000);
setColor(0, 0, 100); // Blue
delay (1000);
}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, 255-red); //I did the 255- because I'm using an anode LED
analogWrite(greenPin, 255-green);
analogWrite(bluePin, 255-blue);
}
If you look at my code, when I try that RGB value my LED red pin won't turn on at all, even though the green and blue pins do light up but very dim. I'm trying to get my red pin to dim to help better fuse colors but it's not working.
Any value below 128 for the red doesn't work, and anything above it turns it on and it acts as if it were 255. Any help would be appreciated! =(