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:
This is my altered Nightlight code under read more: