This commit is contained in:
Zakary Timson 2022-09-20 21:29:50 -04:00
parent dc1ca8099a
commit 1917dc9c9e
6 changed files with 309 additions and 325 deletions

3
.editorconfig Normal file
View File

@ -0,0 +1,3 @@
[*]
indent_style = tab
indent_size = 4

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/.idea/

View File

@ -1,9 +1,11 @@
# Animated Cube
Using multiplexing, I created a 3D cube of blue LED's 4x4x4. It's powered by an Arduino
allowing me to create animations by turning on multiple lights.
Using [multiplexing](https://en.wikipedia.org/wiki/Multiplexing) 64 LEDs have been wired into a 4x4x4 matrix. This
allows for individual control of each LED by controlling a combination of 20 different inputs.
By quickly blinking different lights in a sequence, 3D animations can be created by the matrix.
## Table of Contents
[[_TOC_]]
## Gallery
![led-cube](./picture.jpg)
![led-cube](./gallery/picture.jpg)

View File

Before

Width:  |  Height:  |  Size: 138 KiB

After

Width:  |  Height:  |  Size: 138 KiB

48
v1.ino
View File

@ -1,15 +1,13 @@
#include <avr/pgmspace.h> // allows use of PROGMEM to store patterns in flash
#include <avr/pgmspace.h>
#define CUBESIZE 4
#define PLANESIZE CUBESIZE*CUBESIZE
#define PLANETIME 3333 // time each plane is displayed in us -> 100 Hz refresh
#define TIMECONST 20 // multiplies DisplayTime to get ms - why not =100?
#define TIMECONST 20 // multiplies DisplayTime to get ms
// LED Pattern Table in PROGMEM - last column is display time in 100ms units
// TODO this could be a lot more compact but not with binary pattern representation
// TODO: this could be a lot more compact but not with binary pattern representation
prog_uchar PROGMEM PatternTable[] = {
// blink on and off
B0001,B0000,B0000,B0000,B0001,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
B0011,B0000,B0000,B0000,B0011,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
B0011,B0010,B0000,B0000,B0011,B0010,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
@ -175,39 +173,26 @@ B1111,B1111,B1111,B1111,B1111,B1111,B1111,B1111,B0000,B0000,B0000,B0000,B0000,B0
B1111,B1111,B1111,B1111,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
// this is a dummy element for end of table (duration=0) aka !!!DO NOT TOUCH!!!
B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, 0
};
/*
** Defining pins in array makes it easier to rearrange how cube is wired
** Adjust numbers here until LEDs flash in order - L to R, T to B
** Note that analog inputs 0-5 are also digital outputs 14-19!
** Pin DigitalOut0 (serial RX) and AnalogIn5 are left open for future apps
*/
int LEDPin[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int PlanePin[] = {16, 17, 18, 19};
// initialization
void setup()
{
int pin; // loop counter
// set up LED pins as output (active HIGH)
void setup() {
int pin;
// Select row+column (Set to HIGH)
for (pin = 0; pin < PLANESIZE; pin++) {
pinMode(LEDPin[pin], OUTPUT);
}
// set up plane pins as outputs (active LOW)
// Select plane (Set to LOW)
for (pin = 0; pin < CUBESIZE; pin++) {
pinMode(PlanePin[pin], OUTPUT);
}
}
// display pattern in table until DisplayTime is zero (then repeat)
void loop()
{
// declare variables
void loop() {
byte PatternBuf[PLANESIZE]; // saves current pattern from PatternTable
int PatternIdx;
byte DisplayTime; // time * 100ms to display pattern
@ -218,24 +203,18 @@ int ledrow; // counts LEDs in refresh loop
int ledcol; // counts LEDs in refresh loop
int ledpin; // counts LEDs in refresh loop
// Initialize PatternIdx to beginning of pattern table
PatternIdx = 0;
// loop over entries in pattern table - while DisplayTime>0
do {
// read pattern from PROGMEM and save in array
memcpy_P(PatternBuf, PatternTable+PatternIdx, PLANESIZE);
PatternIdx += PLANESIZE;
// read DisplayTime from PROGMEM and increment index
DisplayTime = pgm_read_byte_near(PatternTable + PatternIdx++);
// compute EndTime from current time (ms) and DisplayTime
EndTime = millis() + ((unsigned long) DisplayTime) * TIMECONST;
// loop while DisplayTime>0 and current time < EndTime
while(millis() < EndTime) {
patbufidx = 0; // reset index counter to beginning of buffer
patbufidx = 0; // reset index to beginning of buffer
// loop over planes
for(plane = 0; plane < CUBESIZE; plane++) {
// turn previous plane off
if (plane == 0) {
digitalWrite( PlanePin[CUBESIZE-1], HIGH );
} else {
@ -253,10 +232,9 @@ patbufidx++;
// turn current plane on
digitalWrite( PlanePin[plane], LOW );
// delay PLANETIME us
delayMicroseconds( PLANETIME );
} // for plane
} // while <EndTime
} while (DisplayTime > 0); // read patterns until time=0 which signals end
}
}
} while (DisplayTime > 0);
}