Skip to toolbar
Smart controlled daisy-chain RGB LEDs

Smart controlled daisy-chain RGB LEDs

Supported by (Turn Off)

Inventing a language of your own

Tutoring 1
Skill 1
Idea 1
No Comments

A bit like when you LARPers head of to UKGE and camp out with the Orcs by the lake, there’s nothing like creating your own language to make you feel like you’ve truly arrived in the Nerd World.

Luckily for us, we need only a really simple language to “talk to” our LEDs.

We already know that they’re going to be “daisy-chained” so the easiest way to control each one individually is to number them, then send a message to just one specific LED.

Sadly our LEDs are pretty dumb things. Their vocabulary consists of “how much red, how much green and how much blue?” That’s all they understand. They have no idea what “orange” is, or what shade “magenta” should be.

So something as simple as “oi, you, number six, give it full beans on the blue and green channels and nothing on the red” should suffice for our language.

Inventing a language of your own

While, in theory, we can have an “unlimited” number of LEDs in a chain (or, at least, until the voltage drop between the power source and the last one is so great as to provide less than around 6.5V into our voltage regulator) in practice, it’d make sense to put an upper limit on the number of LEDs on our chain, just for the sake of keeping our language nice and simple.

I reckon 256 should be plenty LEDs for anyone. It’s also a really nice number to use in 8-bit computing. We can represent and number between 0-255 using just two characters. For the uber-nerdy types, we’re in danger of stumbling into hexadecimal territory here. For the rest of us, we just need to know that, in our simple language, we can use two characters to signify any number up to 255.

So our language will be to blurt out a succession of four numbers.

  • The first is the number of the LED we want to control
  • The second is the amount of red (0 = off, 255 = full power)
  • The third is the amount of green light we want
  • The fourth is the amount of blue
Inventing a language of your own

Using hexadecimal also provides some basic error checking for our system. Because we know that every message “packet” will contain four numbers – never three, that’s too few, and never five, that’s too many, and because we can represent each number with exactly two characters, our first sanity check is that a valid message must always have eight characters (4 x 2  = 8)

So when we receive a message, we first check that it is exactly eight characters long. If it is, we then chop it up into four parts, turn each part into a number and then assign the corresponding amounts of red, blue and green to the appropriate LED.

Simples 😉

Leave a Reply

Supported by (Turn Off)