CubeController is a collection of Python code to control and animate my Raspberry Pi 4x4x4 LED cube. You are free to use it for your own cube, though, which is what the following sections describe.
- A Raspberry Pi
- 20 usable GPIO pins
- Able to light up 16 LEDs at once
- An LED cube
- 4x4x4 in size
- 16 anode-columns wired up to the Pi
- 4 cathode-layers wired up to Pi-controlled transistors
- RPi.GPIO
- Python 3
-
Before using CubeController, you must tell it which pins to use to turn on certain LEDs. Inside
points_display.py
, update thetransistor_layers
andcolumn_grid
arrays to match with your cube. If done correctly, turning on the pins contained intransistor_layers[y]
andcolumn_grid[x][z]
should light up the LED at those coordinates, with the x coordinate starting at the back of the cube, the y coordinate starting at the bottom of the cube, and the z coordinate starting at the right of the cube. -
Next, you may want to create additional animations for your cube. To do so, create a new file inside
patterns/
and import thePattern
base class frompattern.py
, the plotting functions fromplotting.py
, and thesleep()
function fromtime
, along with anything animation-specific. Then, create a new class that inherits fromPattern
. The__init__()
function inside ofPattern
automatically takes two arguments:max_iters
, which tells your animation how many loops to run for, andframe_delay
, which tells your animation how long to wait between frames (this is wheresleep()
becomes handy). Adding any extra arguments requires you to override the__init__()
function. Then, create arun()
method inside your class, which will automatically be called when it's your animation's turn to run. Inside of this, create awhile self.running:
block, add your animation code (making use of theplotting.py
functions), and add a call toself.update_iters()
at the end, which will decide when your animation has run for long enough and updateself.running
accordingly. Once you're done, go intoled_cube.py
and update thesequence
object with an instance of your animation class. -
Finally, when you want to run CubeController, execute
python3 led_cube.py
. You may wait until the entire sequence has finished, or you mayCtrl+C
early.