RGB LED
Controlling a Programmable RGB LED
There are two 5mm RGB LED's soldered on the board. These LED's are interesting in that they are controlled using only a single pin. The LED's are called WS2812B Programmable LED's.
WS2812B is an intelligent control LED where the control circuit and RGB chip are integrated in a single 5mm through hole package. To understand these LEDs, let's walk through how this addressable LED protocol works.
Each separate red, green, and blue LED in a single WS2812B unit is set up to shine at 256 brightness levels, indicated by an 8-bit binary sequence set from 0 to 255. When combined, each LED unit requires three sets of eight brightness bits, or 24 bits, of information for full control. Let us see how it works:
Our micro-controller transmits a sequence of eight green bits, eight red bits, and eight blue bits to the first LED in the series.
When multiple LED's are present, the data sequence that controls the second LED starts directly after the first with red, green and blue data. The sequence continues in that pattern until it illuminates every LED present.
The first LED takes in information for the entire chain of LED's, then passes the same data along without the sequence it applied to itself, transforming the second LED into the first component on the list.
This "new number one" LED unit continues passing information along until there are no more binary LED sequences left.
To demonstrate the above procedure, we need to download and install a library to control these intelligent LED's. The library we will download is Adafruit_NeoPixel.h
from https://github.com/adafruit/Adafruit_NeoPixel
Libraries are often distributed as a ZIP file or folder. The name of the folder is the name of the library. Inside the folder will be a .cpp file, a .h file and often a keywords.txt file, examples folder, and other files required by the library.
There are two ways to install the library:
In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation. Search for Neopixel strip using the search bar. Click on the text area and then select the specific version and install it.
Navigate to the Releases page. Download the latest release. Extract the zip file In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library
Copy the below code, compile and upload:
Last updated