4x4x4 LED Cube Coding Issues
hi, made 4x4x4 led cube connected arduino , wanted make own code it, have few problems... first of new arduino, lot of on head. made led cube anodes layers , cathodes columns, there 4 positives , 16 negatives. found code on internet works cube want make own code using code generator(http://www.robota.nl/en/blog/led-cube-4x4x4-pattern-designer/led-cube-simulation-and-pattern-generator.html). found code(below) used same coding technique. modify code work cube setup? if great!
here's link tutorial on how made 4x4x4 led cube, if have inquiry circuit layout or wiring:
(http://www.instructables.com/id/4x4x4-led-cube-arduino-uno/)
thanks time,
-kyle
connection setup:
the wiring setup resemble graph 3rd dimension. columns, there 2 axes x , y. in addition, layers serve z axis. if straight down top of led cube looks 1st quadrant on graph except origin (1,1) on cube.
columns
[(x,y)-pin]
(1,1)-13
(1,2)-12
(1,3)-11
(1,4)-10
(2,1)-9
(2,2)-8
(2,3)-7
(2,4)-6
(3,1)-5
(3-2)-4
(3-3)-3
(3,4)-2
(4,1)-1
(4,2)-0
(4,3)-a5
(4,4)-a4
layers
[layer-pin]
a-a0
b-a1
c-a2
d-a3
this code want have modified cube:
here's link tutorial on how made 4x4x4 led cube, if have inquiry circuit layout or wiring:
(http://www.instructables.com/id/4x4x4-led-cube-arduino-uno/)
thanks time,
-kyle
connection setup:
the wiring setup resemble graph 3rd dimension. columns, there 2 axes x , y. in addition, layers serve z axis. if straight down top of led cube looks 1st quadrant on graph except origin (1,1) on cube.
columns
[(x,y)-pin]
(1,1)-13
(1,2)-12
(1,3)-11
(1,4)-10
(2,1)-9
(2,2)-8
(2,3)-7
(2,4)-6
(3,1)-5
(3-2)-4
(3-3)-3
(3,4)-2
(4,1)-1
(4,2)-0
(4,3)-a5
(4,4)-a4
layers
[layer-pin]
a-a0
b-a1
c-a2
d-a3
this code want have modified cube:
code: [select]
#include <avr/pgmspace.h> // allows use of progmem store patterns in flash
#define cubesize 4
#define planesize cubesize*cubesize
#define planetime 100 // time each plane displayed in -> 100 hz refresh
#define timeconst 20 // multiplies displaytime ms - why not =100?
// led pattern table in progmem - last column display time in 100ms units
// todo lot more compact not binary pattern representation
prog_uchar progmem patterntable[] = {
//1 //2 //3 //4 //5 //6 //7 //8 //9 //10 //11 //12 //13 //14 //15 //16 //row numbers, useful
b0000,b0000,b0000,b0000,b0000,b0000,b0000,b0000,b0000,b0000,b0000,b0000,b0000,b0000,b0000,b0000,10,//empty set
//this put code patterns
// dummy element 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 easier rearrange how cube wired
** adjust numbers here until leds flash in order - l r, t b
** note analog inputs 0-5 digital outputs 14-19!
** pin digitalout0 (serial rx) , analogin5 left open future apps
*/
int ledpin[] = {13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 14, 15};
int planepin[] = {16, 17, 18, 19};
// initialization
void setup()
{
int pin; // loop counter
// set led pins output (active high)
for (pin=0; pin<planesize; pin++) {
pinmode( ledpin[pin], output );
}
// set plane pins outputs (active low)
for (pin=0; pin<cubesize; pin++) {
pinmode( planepin[pin], output );
}
}
// display pattern in table until displaytime 0 (then repeat)
void loop()
{
// declare variables
byte patternbuf[planesize]; // saves current pattern patterntable
int patternidx;
byte displaytime; // time*100ms display pattern
unsigned long endtime;
int plane; // loop counter cube refresh
int patbufidx; // indexes byte pattern buffer
int ledrow; // counts leds in refresh loop
int ledcol; // counts leds in refresh loop
int ledpin; // counts leds in refresh loop
// initialize patternidx beginning of pattern table
patternidx = 0;
// loop on entries in pattern table - while displaytime>0
do {
// read pattern progmem , save in array
memcpy_p( patternbuf, patterntable+patternidx, planesize );
patternidx += planesize;
// read displaytime progmem , increment index
displaytime = pgm_read_byte_near( patterntable + patternidx++ );
// compute endtime current time (ms) , displaytime
endtime = millis() + ((unsigned long) displaytime) * timeconst;
// loop while displaytime>0 , current time < endtime
while ( millis() < endtime ) {
patbufidx = 0; // reset index counter beginning of buffer
// loop on planes
for (plane=0; plane<cubesize; plane++) {
// turn previous plane off
if (plane==0) {
digitalwrite( planepin[cubesize-1], high );
} else {
digitalwrite( planepin[plane-1], high );
}
// load current plane pattern data ports
ledpin = 0;
for (ledrow=0; ledrow<cubesize; ledrow++) {
for (ledcol=0; ledcol<cubesize; ledcol++) {
digitalwrite( ledpin[ledpin++], patternbuf[patbufidx] & (1 << ledcol) );
}
patbufidx++;
}
// turn current plane on
digitalwrite( planepin[plane], low );
// delay planetime us
delaymicroseconds( planetime );
} // plane
} // while <endtime
} while (displaytime > 0); // read patterns until time=0 signals end
}
can explain using words (instead of links) need ?
example:
before code:
need following changes above code made: (describe changes in terms of hardware , software.
my hardware:
blah blah,
hardware of unmodified code
(hardware difference between hardware unmodified code written , hardware, reason changes)
1- change code [blah blah blah]
after code
example:
before code:
code: [select]
unmodified code
need following changes above code made: (describe changes in terms of hardware , software.
my hardware:
blah blah,
hardware of unmodified code
(hardware difference between hardware unmodified code written , hardware, reason changes)
1- change code [blah blah blah]
after code
code: [select]
modified code here
(has above changes)
Arduino Forum > Using Arduino > LEDs and Multiplexing > 4x4x4 LED Cube Coding Issues
arduino
Comments
Post a Comment