Step 6Code
Most cube code uses direct writes to the columns. The code says that Column X needs to be lit so give it some juice and we're done. That doesn't work when using controller chips.
The controller chips use 4 wires to talk to the Arduino: SPI-in, Clock, Latch, and Enable. I grounded the Enable pin (pin 21) through a resistor (RL) so output is always enabled. I never used the Enable so I took it out of the code. SPI-in is the data in from the Arduino, Clock is a timing signal between the two while they talk, and Latch tells the controller it's time to accept new data.
Each output for each chip is controlled by a 16 bit binary number. For example; sending 1010101010101010 to the controller would cause every other LED on the controller to light. Your code needs to run through everything needed for a display and build that binary number, then send it to the chip. It's easier than it sounds. Technically it's a bunch of bitwise addition, but I'm lousy at bitwise math so I do everything in decimal.
Decimal for the first 16 bits are as follows:
1 << 0 == 1
1 << 1 == 2
1 << 2 == 4
1 << 3 == 8
1 << 4 == 16
1 << 5 == 32
1 << 6 == 64
1 << 7 == 128
1 << 8 == 256
1 << 9 == 512
1 << 10 == 1024
1 << 11 == 2048
1 << 12 == 4096
1 << 13 == 8192
1 << 14 == 16384
1 << 15 == 32768
This means if you want to light up outputs 2 and 10, you add the decimals (2 and 512) together to get 514. Send 514 to the controller and outputs 2 and 10 will light.
But we have more than 16 LEDs so it gets slightly more difficult. We need to build display information for 4 chips. Which is as easy as building it for 1, just do it 3 more times. I use a global variable array to hold the control codes. It's just easier that way.
Once you have all 4 display codes ready to send, drop the latch (set it to LOW) and start sending the codes. You need to send the last one first. Send the codes for chip 4, then 3, then 2, then 1, then set the Latch to HIGH again. Since the Enable pin is always connected to ground, the display is changed immediately.
Most cube code I've seen on Instructables, and the web in general, consists of a giant block of code set to perform a pre-set animation. That works fine for smaller cubes but needing to store, read, and send 512 bits of binary every time you want to change the display takes up a lot of memory. The Arduino couldn't handle more than a few frames. So I wrote some simple functions to show the cube in action that rely on calculation rather than pre-set animations. I included a small animation to show how it is done, but I'll leave it to you to build your own displays.
cube8x8x8.pde is the Arduino code. I plan to continue adding functions to the code and will update the program periodically.
matrix8x8.pde is a program in Processing to build your own displays. The first number given goes into pattern1[], second into pattern2[], etc.
The datasheet for the A6276EA is available at:
http://www.allegromicro.com/en/Products/Part_Numbers/6276/6276.pdf
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|












































