Cleanup
This commit is contained in:
parent
dc1ca8099a
commit
1917dc9c9e
3
.editorconfig
Normal file
3
.editorconfig
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[*]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/.idea/
|
@ -1,9 +1,11 @@
|
|||||||
# Animated Cube
|
# Animated Cube
|
||||||
Using multiplexing, I created a 3D cube of blue LED's 4x4x4. It's powered by an Arduino
|
Using [multiplexing](https://en.wikipedia.org/wiki/Multiplexing) 64 LEDs have been wired into a 4x4x4 matrix. This
|
||||||
allowing me to create animations by turning on multiple lights.
|
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
|
## Table of Contents
|
||||||
[[_TOC_]]
|
[[_TOC_]]
|
||||||
|
|
||||||
## Gallery
|
## Gallery
|
||||||
![led-cube](./picture.jpg)
|
![led-cube](./gallery/picture.jpg)
|
||||||
|
Before Width: | Height: | Size: 138 KiB After Width: | Height: | Size: 138 KiB |
48
v1.ino
48
v1.ino
@ -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 CUBESIZE 4
|
||||||
#define PLANESIZE CUBESIZE*CUBESIZE
|
#define PLANESIZE CUBESIZE*CUBESIZE
|
||||||
#define PLANETIME 3333 // time each plane is displayed in us -> 100 Hz refresh
|
#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
|
// 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[] = {
|
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,
|
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,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,
|
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,
|
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,
|
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!!!
|
// 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
|
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 LEDPin[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||||
int PlanePin[] = {16, 17, 18, 19};
|
int PlanePin[] = {16, 17, 18, 19};
|
||||||
|
|
||||||
// initialization
|
void setup() {
|
||||||
void setup()
|
int pin;
|
||||||
{
|
// Select row+column (Set to HIGH)
|
||||||
int pin; // loop counter
|
|
||||||
// set up LED pins as output (active HIGH)
|
|
||||||
for (pin = 0; pin < PLANESIZE; pin++) {
|
for (pin = 0; pin < PLANESIZE; pin++) {
|
||||||
pinMode(LEDPin[pin], OUTPUT);
|
pinMode(LEDPin[pin], OUTPUT);
|
||||||
}
|
}
|
||||||
// set up plane pins as outputs (active LOW)
|
// Select plane (Set to LOW)
|
||||||
for (pin = 0; pin < CUBESIZE; pin++) {
|
for (pin = 0; pin < CUBESIZE; pin++) {
|
||||||
pinMode(PlanePin[pin], OUTPUT);
|
pinMode(PlanePin[pin], OUTPUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// display pattern in table until DisplayTime is zero (then repeat)
|
void loop() {
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
// declare variables
|
|
||||||
byte PatternBuf[PLANESIZE]; // saves current pattern from PatternTable
|
byte PatternBuf[PLANESIZE]; // saves current pattern from PatternTable
|
||||||
int PatternIdx;
|
int PatternIdx;
|
||||||
byte DisplayTime; // time * 100ms to display pattern
|
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 ledcol; // counts LEDs in refresh loop
|
||||||
int ledpin; // counts LEDs in refresh loop
|
int ledpin; // counts LEDs in refresh loop
|
||||||
|
|
||||||
// Initialize PatternIdx to beginning of pattern table
|
|
||||||
PatternIdx = 0;
|
PatternIdx = 0;
|
||||||
// loop over entries in pattern table - while DisplayTime>0
|
|
||||||
do {
|
do {
|
||||||
// read pattern from PROGMEM and save in array
|
|
||||||
memcpy_P(PatternBuf, PatternTable+PatternIdx, PLANESIZE);
|
memcpy_P(PatternBuf, PatternTable+PatternIdx, PLANESIZE);
|
||||||
PatternIdx += PLANESIZE;
|
PatternIdx += PLANESIZE;
|
||||||
// read DisplayTime from PROGMEM and increment index
|
|
||||||
DisplayTime = pgm_read_byte_near(PatternTable + PatternIdx++);
|
DisplayTime = pgm_read_byte_near(PatternTable + PatternIdx++);
|
||||||
// compute EndTime from current time (ms) and DisplayTime
|
|
||||||
EndTime = millis() + ((unsigned long) DisplayTime) * TIMECONST;
|
EndTime = millis() + ((unsigned long) DisplayTime) * TIMECONST;
|
||||||
|
|
||||||
// loop while DisplayTime>0 and current time < EndTime
|
|
||||||
while(millis() < EndTime) {
|
while(millis() < EndTime) {
|
||||||
patbufidx = 0; // reset index counter to beginning of buffer
|
patbufidx = 0; // reset index to beginning of buffer
|
||||||
|
|
||||||
// loop over planes
|
// loop over planes
|
||||||
for(plane = 0; plane < CUBESIZE; plane++) {
|
for(plane = 0; plane < CUBESIZE; plane++) {
|
||||||
// turn previous plane off
|
|
||||||
if (plane == 0) {
|
if (plane == 0) {
|
||||||
digitalWrite( PlanePin[CUBESIZE-1], HIGH );
|
digitalWrite( PlanePin[CUBESIZE-1], HIGH );
|
||||||
} else {
|
} else {
|
||||||
@ -253,10 +232,9 @@ patbufidx++;
|
|||||||
|
|
||||||
// turn current plane on
|
// turn current plane on
|
||||||
digitalWrite( PlanePin[plane], LOW );
|
digitalWrite( PlanePin[plane], LOW );
|
||||||
// delay PLANETIME us
|
|
||||||
delayMicroseconds( PLANETIME );
|
delayMicroseconds( PLANETIME );
|
||||||
} // for plane
|
}
|
||||||
} // while <EndTime
|
}
|
||||||
} while (DisplayTime > 0); // read patterns until time=0 which signals end
|
} while (DisplayTime > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user