Thursday, March 20, 2014

Radio Shack DIY 3 X 3 LED Cube Project

This project is really fun! Lots of people have posted their experience putting it together so I won't do that, but after recovering from a bit of soldering problems what I find challenging, or just tedious, is figuring out exactly what hex codes to use to create arrays for you own programs. I did figure out lighting up individual LEDs 1-9 on each level to make these two patterns, shown one after the other here:

So to make it easier for others here are the codes for individual LEDs:

// 1-9
// * 0x001 = 1
// * 0x002 = 2
// * 0x004 = 3
// * 0x008 = 4
// * 0x010 = 5
// * 0x020 = 6
// * 0x040 = 7
// * 0x080 = 8
// * 0x100 = 9

And here's the array that makes the LEDs circle around:
//        Spiral 2, set page to 32
                                 {0x001,0x000,0x000,0x1ff},
                                 {0x002,0x000,0x000,0x1ff},
                                 {0x004,0x000,0x000,0x1ff},
                                 {0x020,0x000,0x000,0x1ff},
                                 {0x100,0x000,0x000,0x1ff},
                                 {0x080,0x000,0x000,0x1ff},
                                 {0x040,0x000,0x000,0x1ff},
                                 {0x008,0x000,0x000,0x1ff},

                                 {0x000,0x001,0x000,0x1ff},
                                 {0x000,0x002,0x000,0x1ff},
                                 {0x000,0x004,0x000,0x1ff},
                                 {0x000,0x020,0x000,0x1ff},
                                 {0x000,0x100,0x000,0x1ff},
                                 {0x000,0x080,0x000,0x1ff},
                                 {0x000,0x040,0x000,0x1ff},
                                 {0x000,0x008,0x000,0x1ff},

                                 {0x000,0x000,0x001,0x1ff},
                                 {0x000,0x000,0x002,0x1ff},
                                 {0x000,0x000,0x004,0x1ff},
                                 {0x000,0x000,0x020,0x1ff},
                                 {0x000,0x000,0x100,0x1ff},
                                 {0x000,0x000,0x080,0x1ff},
                                 {0x000,0x000,0x040,0x1ff},
                                 {0x000,0x000,0x008,0x1ff},

                                 {0x000,0x001,0x000,0x1ff},
                                 {0x000,0x002,0x000,0x1ff},
                                 {0x000,0x004,0x000,0x1ff},
                                 {0x000,0x020,0x000,0x1ff},
                                 {0x000,0x100,0x000,0x1ff},
                                 {0x000,0x080,0x000,0x1ff},
                                 {0x000,0x040,0x000,0x1ff},
                                 {0x000,0x008,0x000,0x1ff},

Now how about the hex codes for combinations of LEDs? Brad here explained the method for calculating them but I didn't get it until I read over it a few times. Once we have the base 10 (DEC) value for each of 1-9 (see Brad's table), just add those for the numbers you want to display, then convert the total to HEX, like here. For example, if I want 4 and 6 to light, 8 + 32 = 40, converted to HEX = 28. So this will do it for that element: 0x028.
Update: here is a modified sketch for running different tables more easily. Different patterns are individual tables, so call the pattern() function with a table passed as argument, along with how many lines it uses.

No comments :