1
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ That did the trick! Thank you, I should have known I even flipped the digitalWrite()'s to LOW instead of HIGH. \$\endgroup\$ – chrisw Nov 10 '11 at 4:20
0
\$\begingroup\$

Just to add some clarification on why the analogWrite did not work as expected. You state the LED's are common anode, and so the RGB pins going to the arduino are negative wires. Therefore, when you write analog 255 (or digital high) to the pin, you are turning off that color to the led - because it is not grounded and the circuit is broken. When you write low to the pin, you are grounding it (sinking it) and the circuit is complete, which turns the LED wire on.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.