If you have done any Internet programming, you will probably be aware that colors are often represented as a 'hex' number. For example the color red has the number #FF0000. You can find the numbers associated with a particular color using tables like these: https://htmlcolorcodes.com/color-names/
The six digits of the number are actually three pairs of numbers; the first pair being the red component of the color, the next two digits the green part and the final pair the blue part. Red is #FF0000, because its maximum red (FF is 255 in hex) and it has no green or blue part.

It would be pretty useful to be able to dial up one of these color numbers so that it is displayed on the RGB LED.

Let's try and make the color indigo (#4B0082).

The red, green and blue parts of indigo are (in hex) 4B, 00 and 82 respectively. We can plug those into the 'setColor' function like this:
setColor(0x4B, 0x0, 0x82);  // indigo
We have used hex numbers for the three parts of the color by putting '0x' in front of them.

Try adding a few colors of your own to the 'loop' function. Don't forget to add a delay after each one.

This guide was first published on Nov 30, 2012. It was last updated on Oct 02, 2012.

This page (Using Internet Colors) was last updated on Oct 02, 2012.

Text editor powered by tinymce.