BlocklyProp makes it very easy to control individual WS2812B RGB LEDs. These LED modules may be daisy-chained together by connecting one module’s serial-out pin to the next module’s serial-in pin. Each LED has 16 million different colors and it’s own “address” so you can identify which one to control in your BlocklyProp program. The difficult work to be done by the C code libraries used within BlocklyProp. The WS2812 RGB LEDs may be faded, dimmed, pulsed, and scrolled individually or as groups.
This project is separated into two parts that demonstrate different ways to use these LEDs with BlocklyProp. If you are interested in going further, there is a third part to this series (Rainbows and Robotics with WS2812 LED Strip Lighting) that uses LED strips with Blockly and the S3.
Did You Know?
WS2812 RGB LEDs were used with the Propeller multicore microcontroller in the Bud Light PAC-MANTM commercial, originally aired during Super Bowl XLIX, to light up full-size human “ghosts” on roller skates (click here to read our news story about it). Each costume has several thousand LEDs to show when the ghost is in chase mode or ready to be eaten by PAC-MAN.
Common applications of single LEDs are to display various states of your program for human feedback, but the larger “rolls” of LED tape have pre-made connections to power, ground and data. You can use the Blockly system to control these systems, too.
- (3 or more) - WS2812 RGB LED (#28085)
- (1) FLiP Module or Propeller Activity Board (original or WX)
Parallax’s WS2812 RGB LEDs are sold in 10-packs (#28086) or individually (#28085). To keep your costs low, the 3-pin headers need to be soldered on after you receive them. Students are always interested in being able to solder and build; this process is an important and rewarding step in building the circuit. The soldering process is very easy, too.
- Propeller P0 to #1 WS2812 RGB LED SI (Serial In)
- First RGB LED’s SO (serial out) to second RGB LED’s SI
- Second RGB LED SO to third RGB LED SI
- RGB LED 5V connections to 5VDC
- RGB LED GND connections to Propeller FLiP module GND pin
The WS2812 RGB LED blocks are found in the COMMUNICATE menu and documented in the RGB LED BlocklyProp reference section. Setting the blocks is simply a matter of initializing the communication pin and setting the number of LEDs. The sequence begins at number one.
The single biggest technical challenge with these LEDs is attempting to control an LED which isn’t present. The example circuit has three LEDs. If you specify four or more LEDs in the RGB LED init block the daisy-chained integrated circuits will fail to enumerate themselves and your LEDs will remain off regardless of the control signal you send.
Program your circuit with the sample program WS2812 Setting Color to set the three LEDs with red, white and blue. Experiment with different colors!
Dimming the LEDs
Immediately you’ll likely notice that these LEDs are simply too bright and that perhaps you'd like to apply some dimming. By choosing BlocklyProp’s bitwise block from the Numbers menu you can mix any color with another. Mix each color with a grey shade to dim the LED. This has another benefit - the current draw of each LED is much lower, enabling you to control more LEDs from your computer’s USB port which is limited to around 500 mA.
A modification of the above program is the BlocklyProp program Simple Color Control with Dimming from the reference section.
Color pulsing is similar to dimming - but it’s more like a form of advanced brightness control. Instead of adding a single color (like grey, above), increasing the amount of the color from 0 to 255 drives the LED from off to full brightness. This can easily be done by using a repeat loop for each LED, one at a time. The WS2812 Color Pulsing code example demonstrates this capability; download it here:
BlocklyProp has a Random number block where you can set the range of values. The WS2812 Random Colors code example demonstrates this feature.