The connection to the LED cube is via a serial-to-parallel shiftregister. This is a way to handle lots of connections with only a few outputs from the microcontroller - in this case the Arduino. I use the 74HC595 shiftregister as described in this tutorial. Using two cascaded shiftregisters means you will have to use the shiftOut command two times in succession in order to service all 16 outputs.
As mentioned in the previous post we will use the concept of multiplexing to light up all the LEDs. This means we will turn on one layer at a time so fast you can't see the switching. The sequence in my code is as follows:
- Turn off LEDS
- shiftOut 2 times for all 16 LEDs in the layer - setting high the wanted LEDs
- Turn on the given layer by pulling the common cathode low.
- wait a bit
- start over.
With the configuration of the LEDs in the cube an LED will light when a HIGH is set on the data output (the 2 bytes shifted out) and a LOW set on the Layer Select bits (separate output).
I've put this sequence in a function of its own that will 'repaint' the 'image' on the cube a given amount of time - void setCube(int* image, int repeats) This also takes the 'image' as a parameter which is a pointer to an array of 4 integers that tells which LEDs to turn on in the cube. An integer for each layer.
With this it is now possible to visualize any pattern on the 4x4x4 cube. Let your imagination get to work :)
With this it is now possible to visualize any pattern on the 4x4x4 cube. Let your imagination get to work :)
Demo source code is given as an Arduino sketch
Below is a video of the demo sketch in action.
Ingen kommentarer:
Send en kommentar