Showing posts with label helpful. Show all posts
Showing posts with label helpful. Show all posts

Saturday, November 7, 2015

RGB LED Problems Fixed - Explanation - Jen Herrera

So this isn't an assigned post and I don't know if it will do anything for me point-wise, but I wanted to share some information for the other people who might still be having problems with exercises involving RGB LEDs.

These things have been vexing me the whole semester. Especially when I went back to make 2-6 Nightlight work. (also temperature and processing sketches)

I would wire my LED just like in the diagrams; Only some of the colors would work, others would just be off.
I did some research and found out that RGB LEDs come in common cathode and common anode varieties.
The wiring diagram is for a common cathode type LED. The second pin in this type goes to ground. This is not the type that I have. I theorized that I might have the other type, so I hooked up the second pin to 5V instead and it worked for the whole cycle! Except that the colors weren't what they were supposed to be.

That's because with a common anode the RGB pins in the code should be LOW not HIGH like it is for common cathode. So you can go back in the code and switch all the modes. For the ones that use numbers, switch 127 and 0, and for white, make them all 0. (see working code below)

A quick test to see if your LED is common anode like mine was: Connect the longest pin straight to 5V and use the resistor to make the RGB legs light up individually:
If it does work that way, you can use this knowledge moving forward to alter codes and and wiring for all exercised with the RGB LED. :) 

This is my altered Nightlight code under read more: