Revisiting Device Independent Control for LED Cubes

LED Cube 8x8x8

Some time ago, I wrote about device independent control of monochrome LED cubes (see this previous blog post which contains information referenced in this article).

Recently, someone contacted me about extending this framework to color cubes for a project they were considering. As it turn out, this was relatively straightforward and has added additional capability to the existing MD_Cubo library.

My correspondent had obtained a zirrfa 4x4x4 RGB LED cube. This is a relatively low cost kit that comes with its own processor that runs a looping ‘demo’. However, it also has a serial port that allows an external processor to stop the demo and manage the displays through this on-board processor. In terms of the last article, this is a ‘set and forget‘ architecture, as the refresh of the cube is handled by secondary hardware components rather than the Arduino processor.

So what’s different with a color cube?

The only difference between an on/off LED cube and a color cube is … the colored LED!

So turning the LED on/off now becomes a matter of setting a LED to a specific color. Some thought also reveals that an on/off cube is a special case of a colored cube – it just has 2 colors (black for off and non-black for on). A monochrome cube can therefore be mapped to a color cube using just 2 colors.

So essentially the task turned into evolving the core class methods from a boolean parameter (on/off) for LED state to a 32-bit integer that provides the desired RGB color. The old boolean setVoxel() is now written in terms of an overloaded RGB setVoxel(), using the default RGB colors for on and off.

It is also important to realise that animations for monochrome cubes exploit on/off patterns while animations for color cubes will leverage color changes. Trying to map these animations to each other would result in every colored LED being ‘on’ in monochrome space. Essentially, the whole monochrome cube could be lit most of the time when showing the color animation. So a new method (isColorCube()) is needed that allows the programmer to determine whether the cube being programmed supports color.

The addition of some new macros to allow packing and unpacking RGB values in a standard manner and the definition of a whole lot of standard colors rounded out the required changes.

Once again, the extensibility of C++ class inheritance makes it easy to extend the class around the common core with minimal changes needed to the code for the existing cubes.

Advertisements

3 thoughts on “Revisiting Device Independent Control for LED Cubes

  1. Martin Dow

    Hey Marco! I have a question for a project related to the RGB Colour Cube and arduino. I’ve read through your code for LED RGB smooth colour transitions and I’m just wondering how editable it is. I’m trying to change the colour of an LED as it moves around a room. We have optitrack cameras set up which communicate with Unity.
    The first step will be obtaining coordinates from Unity and transferring them to arduino, where hopefully they can be used to change the RGB values (assigned to x,y,z)
    Fundamentally I’m trying to create a virtual colour cube in a room (that you can’t see but interacts with an LED), ideally with dimensions of 2.55×2.55×2.55 metres to relate to a colour scale of 0-255.

    How much would the colour transition code have to change so that it no longer runs a cycle, but instead reacts to incoming coordinates every second?

    I’d love to hear from you!
    Martin

    Like

    1. Should be a straightforward exercise. Without the cycling, setting the color of the cube is just a matter of using the coordinates sent to set the LED color. There is no point in using the code from the article. A better place to start is one of the simple RGB examples the come with Arduino. The complexity is in the communications between your computer and the moving RGB LED.

      Like

  2. Peter Newman

    Another fabulous project Marco and I thank you. I have always wanted to do an 8 x 8 x 8 LED cube but the control code was always a limiting factor for a beginner like myself. Your library with the JolliCube seems like the perfect match.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s