Hey, wouldn't it be awesome if I could connect a string of multicolor LEDs to a little computer and control the LEDs over my home network? Yes, as a matter of fact, that would be an excellent thing to do.
Step 1: Aquire LEDs
For this experiment, I purchase two strips of 50 ws2801 Pixel LEDs from a merchant in China and after a few weeks, the LEDs arrived and it was time to get hacking.
Step 2: Hack Some Code
The software for controlling the LEDs needed to have the following features:
- a Web UI so that I could control the LEDs with any device connected to my home network.
- a simple API that would allow controlling the LEDs with a GET request from any programming language
To meet my needs, I opted to use the Ruby programming language for the server and jQueryUI for the Web Interface. This decision was based on the Ruby language's standard library webrick module which makes it very easy to create a webserver that serves static content, and also makes it trivial to map URLs to specific functions and methods.
The end result is GLMR, the Glrm Light Manipulation Regulator. Wow, what a crappy recursive backronym. Honestly, I constantly forget what the 'R' stands for and I have to look it up.
The Web UI
There isn't too much to the built in Web UI. Enter a hexadecimal, or adjust the RGB sliders and then click Set to change all of the LEDs to the selected color, or click Fade to slowly fade the LEDs to the selected color.
There are also 3 modes for the LEDs:
- Chase: one LED is illuminated at a time across the length of the LED string
- Full: all LEDs are illuminated
- Twinkle: the LEDs randomly turn on and off
Using the API
Since the browser on my n900 is getting a bit old, I decided to write a Python Qt application that uses the GLMR API and it works wonderfully! Thanks Qt!
Wait a second! If the API is so simple, why don't I have more ways to control the LEDs? Aha! I'm one step ahead of you.
Remember Blather the speech recognizer that runs commands? Well, I've configured Blather to control the LEDs and here is the video of Blather and GLMR working together.
Booyah!
Now quit reading, and go hack some code ... and some LEDs