After having previously built a 3 x 3 x 3 LED cube and controlling it via nine anode pins (columns) and three cathode pins (levels) - I hope that makes sense, I am now trying to design a 4 x 4 x 4 cube using two 74HC595 shift registers for the sixteen LED’s of the planes and either four transistors or a 595 / ULN2803 combination for the levels. Initially I have constructed a 4 x 4 matrix with the sixteen cathodes in series with each other and all connected to ground and each of the sixteen SR outputs consecutively connected to the sixteen LED anodes. i.e. daisy chained.
I have been using shiftOut and trying different coding techniques to control the matrix. I have tried -
- one dimensional arrays with for loops
- two dimensional arrays
- bit shifting right and left through bytes
- declaring functions that access two dimensional arrays
I have tried having both shift registers clock, latch and data lines connected in parallel but found it too limiting as the two halves of the matrix obviously displayed the same pattern so therefore I am having them daisy chained.
I suppose I am just asking for suggestions as to how other people have approached coding when using SR’s with small cubes like this. Here is a sample of the types of coding I have been trying so far. Not very exciting I know but I’m all out of ideas. With hindsight, maybe this is not a practical way to use SR’s to control a cube, and I haven’t even thought too much about level control yet, vis-à-vis coding. Any suggestions would be greatly appreciated, Pedro.
// EXAMPLE 1
int dataPin = 8; // connect to pin 14 of the SR
int clockPin = 12; // connect to pin 11 of the SR
int latchPin = 11; // connect to pin 12 of the SR
int digit[] = {B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001,};
void setup()
{
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
for (int x = 0; x < 7; x++)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, digit [x]);
digitalWrite(latchPin, HIGH);
delay(1000);
}
}
////////////////////////////////////////////////////////////////
// EXAMPLE 2
int pinMatrix[4][4] = {{B10000000,B01000000,B00100000,B00010000},
{B00001000,B01000100,B00100010,B00010001},
{B10000001,B01000010,B00100100,B00011000},
{B11000000,B01100110,B10011001,B00011000}};
void loop()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST,pinMatrix[3][2] );
digitalWrite(latchPin, HIGH);
delay(1000);
/////////////////////////////////////////////////////////////////
// EXAMPLE 3
int pinMatrix[4][4] = {{B10000000,B01000000,B00100000,B00010000},
{B00001000,B01000100,B00100010,B00010001},
{B10000001,B01000010,B00100100,B00011000},
{B11111001,B10011111,B11111111,B00000000}};
void loop()
{
inner();
delay(100);
outer();
delay(100);
}
void inner()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST,pinMatrix[3][2] );
digitalWrite(latchPin, HIGH);
delay(100);
}
void outer()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST,pinMatrix[3][3] );
digitalWrite(latchPin, HIGH);
delay(100);
}
/////////////////////////////////////////////////////////////////
// EXAMPLE 4
int digit = B10000000;
void loop()
{
for (int x = 0; x < 7; x++)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, digit >> x);
digitalWrite(latchPin, HIGH);
delay(1000);
}
}