Electronic – arduino – Anode RGB LED Arduino Hookup

arduinodiodesled

My question is regarding the hookup of a radioshack bright rgb anode led. I have the led common going to a 5v supply and the other pins are going through a 330ohm resistor to 3 PWM output pins (9,10,11 on the Arduino Uno). I set the pinMode() on each pin to OUTPUT, and then I do a "analogWrite(RED_PIN, 255);" and set the other color pins at zero. It should be red, instead it's dark purple. If I do a "digitalWrite(RED_PIN, LOW);" the red led is fully lit. My question is why is the digitalWrite() working and the analogWrite() not? I am new to electronics so excuse me if I used the wrong terminology, I'll do my best to clarify.

Best Answer

Setting the PWM duty cycle to 255 is the opposite of the digital write with low. The duty cycle of 255 means the pin is driven high (5v) 100% of the time. I suspect if you reverse your logic of the Analog writes you will get your intended results.