Go Down

Topic: RGB LED and PWM pins does not work properly (Read 262 times) previous topic - next topic

Jymmy097

Hi everybody!

I have this image which describes the cables I've "attached" to my Arduino Mega to control an RGB LED.
I get something very strange:
when I write
analogWrite(RED, 0)
the LED becomes red and not set the RED component of the color to 0.
I'm a bit confused... :~ :~
If I write
analogWrite(RED, 255)
the LED turn itself off.
(in these examples, the others colors are set to 0. Really.... 0. They are not visible).

I have an Arduino Mega and I've connected the RED to 8, GREEN to 9 and BLUE to 10 and Ground to 5V port.

What is the mistake?

Thanks a lot!

Jymmy

AWOL

Common anode LED?
The behaviour you describe sounds perfectly normal.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Jymmy097

I've seen some tuts that explain that I have to set the colour with analogWrite(colour, 0 if I have to turn off that colour and vice versa.
So that seemed a strange behavior. To avoid errors, I post the image of my led here (it's attached!)

Thanks.

AWOL

If the LED is common anode ( impossible to tell from the photo) then the analogWrite sinks current, so the action of analogWrite is inverted - 0 turns the LED on full, and 255 turns it off.
If you want to write, say, 25/255 brightness, and a variable "brightness" contains 25, then analogWrite (redPin, 255 - brightness);
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy