Smart Addressable LEDs

What is a “smart LED”?

A smart LED is a LED that takes in data from a board (Like the Brainpad) and uses that data to set the specified LEDs to turn on different colors.

There are multiple ways to control these type of LEDs and multiple ways these are programmed. In this example, the smart LEDs use the “LPD8806” chip so make sure that is what you have if you want to use this extension, other than that, the following info will be universal.

Understanding the smart LEDs

Depending on what you bought, you will either have a strip or a matrix of LEDs. While this doesn’t change the code, this changes how the LEDs are organized. In a strip, LEDs are ordered from Left to Right while Matrixes are ordered Top to Bottom, then Bottom to top in a snake-like pattern.

  • Strip
  • Matrix

Wiring the LEDs and understanding SPI

So you got your set of LEDs and you’re ready to wire them to the Brainpad. You should have 4 wires, GND(Ground), 5V(Five Volts/Power), DI(Data In) and CI(Clock In). While Ground and 5 volts are straightforward, DI and CI are specific to the data type we are using, SPI. Without going too offtopic, SPI consists of the Brainpad pins MOSI (Master Out, Slave In), MISO (Master In, Slave Out), and SCK (Serial Clock). Located on the left header. SPI can be used for communication between two devices where both can be sender and receiver. In this case, however, we won’t be receiving any data from these LEDs so, our Brainpad will be the Master sending OUT while the LED Slave goes IN, in short, we will be using the MOSI pin to send data to the Data In(DI) pin on the LED. Which leaves us with CI(Clock In) and SCK(Serial Clock). While it is obvious this lines up because it is the only wire left unplugged, the reason for this clock wire is so the Brainpad can tell the LED how fast it will be sending data. Without it, nothing will show up on the LEDs you have.

Installing the extension

If you are new to Microsoft MakeCode or forgot how to install extensions check out our guide here.

Here is the link if you already know how to install extensions or want to view the extension files on our Github.

Using the extension

Once the extension is added, you will see the “Set led” function. In the following example, we are going to set the third LED to the color red.

There are also 3 other functions. “Clear led (number)” which clears that specific LED, “Clear all LEDs” which clears all of them and “Set max LED length to (number)”. This last function would run ON START and is only if you have more than 10 LEDs. The default 10 value is just a placeholder but you shouldn’t have any issues with LEDs less than 10.

IMPORTANT: You can set as many LEDs as you want but 5 volts won’t be able to power 100 LEDs. In this case, you will have to supply the voltage from a source that is more than 5 volts which is why your LED strip should say “5v+

Get coding!

Now that we know how the Brainpad communicates with the LED strip, how it is wired and how the extension works, take a look at this quick example showing off all the colors and use it as a test!

Start With This MakeCode Example