I am working on rewriting some code to work with my version of a 3d matrix RGB cube. This is chipkit UC32 code.
main refresh routines use the following array
// The cube matrix below stores the status of each LED in the cube
// [column 0-7] [panel 0-7] [layer 0-7] [red, green, blue color components]
// Each of the 3 color components can vary from 0 to 63, giving us approx. 250,000 possible color variations
byte cube[8][8][8][3];
Here is the refresh routine as it stands now. I currently have cubeStructure set to 0
uint32_t refreshCube(uint32_t currentTime) {
byte red, green, blue;
for (byte count=0; count<6; count++){ // BAM counter; each increment doubles the time the LED is on, starting at 5 microsecs.
digitalWrite(Latch, LOW ); //make sure outputs are latched
LATDCLR = CLK|SDIR|SDIG|SDIB;
modeNormal();
if (cubeStructure==0){
LATDSET = OE;// ENABLE OUTPUT
for (byte layer=0; layer<8; layer++){ // scan thru each layer
for (byte panel=0; panel<8; panel++){ // scan thru every panel
for (byte column=0; column<8; column++){ // scan thru every column
//-------------------------------------------------------------------
red = cube[column][panel][layer][0]; // get its red component
if ((red & 1<<count)>0) { // BAM it and shift it out
LATDSET |= SDIR;
}
LATDSET = CLK; //Clock the data in.
_nop();
LATDCLR = CLK|SDIR|SDIG|SDIB;
//-------------------------------------------------------------------
LATECLR = LAYER[7]; // turn on layer
green = cube[column][panel][layer][1]; // get its green component
if ((green & 1<<count)>0) { // BAM it and shift it out
LATDSET |= SDIR;
}
LATDSET = CLK; //Clock the data in.
_nop();
LATDCLR = CLK|SDIR|SDIG|SDIB;
LATESET = LAYER[7]; // turn on layer
//------------------------------------------------------------------
blue = cube[column][panel][layer][2]; // get its blue component
if ((blue & 1<<count)>0) { // BAM it and shift it out
LATDSET |= SDIR;
}
LATDSET = CLK; //Clock the data in.
_nop();
LATDCLR = CLK|SDIR|SDIG|SDIB;
} // end of panel loop
} // end of col loop
// 595 Shift Register Anode Control
// Shifts out current anode byte on
// bit at a time.
for (int b=0; b<8; b++){
if (bitRead(anodeLevel[layer],b)){
LATDSET |= SDIR;
}
LATDSET = CLK; //Clock the data in.
_nop();
LATDCLR = CLK|SDIR|SDIG|SDIB;
} // END ANODE FOR LOOP
// Pulse Latch Pin High
// To Latch the data
LATDSET = LE;
_nop();
LATDCLR = LE;
_nop();
LATDCLR = OE; // ENABLE OUTPUT
LATECLR = LAYER[layer]; // turn on layer
//here count sets time the layer is on
//starting with 10 microsecs and
//ending at 32*10 or 320 microsecs.
delayMicroseconds((1<<count)*10);
LATDSET = OE; // DISABLE OUTPUT
LATESET = LAYER[layer]; //turn off layer
}
}
else {
// Disable Outputs.
LATDSET = OE;
// Red DATA loop
// Scans through cube and outputs the data to the
// TLC5916 Shift registers
// Data is output as a single chain
// 24 bytes of data shifted as RED byte GREEN byte BLUE byte pattern
// SHIFT OUT 8 RED BYTES
//
for (byte layer=0; layer<8; layer++){ // scan thru each layer
for (byte panel=0; panel<8; panel++){ // scan thru every panel
for (byte column=0; column<8; column++){ // scan thru every column
Serial.print(column);
Serial.print("\t");
Serial.print(panel);
Serial.print("\t");
Serial.print(layer);
Serial.println("\t");
// red-----------------------------------------------------
red = cube[column][panel][layer][0]; // get its red component
if ((red & 1<<count)>0) { // BAM it and shift it out
LATDSET |= SDIR;
}
} // end RED column loop
LATDSET = CLK; //Clock the red data in.
_nop();
LATDCLR = CLK|SDIR|SDIG|SDIB;
//******************************************************************************************
for (byte column=0; column<8; column++){ // scan thru every column
Serial.print(column);
Serial.print("\t");
Serial.print(panel);
Serial.print("\t");
Serial.print(layer);
Serial.println("\t");
// red-----------------------------------------------------
green = cube[column][panel][layer][1]; // get its red component
if ((green & 1<<count)>0) { // BAM it and shift it out
LATDSET |= SDIR;
}
} // end green column loop
LATDSET = CLK; //Clock the green data in.
_nop();
LATDCLR = CLK|SDIR|SDIG|SDIB;
//******************************************************************************************
for (byte column=0; column<8; column++){ // scan thru every column
Serial.print(column);
Serial.print("\t");
Serial.print(panel);
Serial.print("\t");
Serial.print(layer);
Serial.println("\t");
// blue-----------------------------------------------------
blue = cube[column][panel][layer][2]; // get its red component
if ((blue & 1<<count)>0) { // BAM it and shift it out
LATDSET |= SDIR;
}
} // end RED column loop
LATDSET = CLK; //Clock the blue data in.
_nop();
LATDCLR = CLK|SDIR|SDIG|SDIB;
//**************************************************************************************
} // DO NEXT PANEL
// 595 Shift Register Anode Control
// Shifts out current anode byte on
// bit at a time.
for (int b=0; b<8; b++){
if (bitRead(anodeLevel[layer],b)){
LATDSET |= SDIR;
}
LATDSET = CLK; //Clock the data in.
_nop();
LATDCLR = CLK|SDIR|SDIG|SDIB;
} // END ANODE FOR LOOP
// Pulse Latch Pin High
// To Latch the data
LATDSET = LE;
_nop();
LATDCLR = LE;
_nop();
LATDCLR = OE; // ENABLE OUTPUT
LATECLR = LAYER[layer]; // turn on layer
//here count sets time the layer is on
//starting with 10 microsecs and
//ending at 32*10 or 320 microsecs.
delayMicroseconds((1<<count)*10);
LATDSET = OE; // DISABLE OUTPUT
LATESET = LAYER[layer]; //turn off layer
} //end layer loop
} // end else
} // end bam loop
My problem:
The code as it stands is sending out the data now as 1 bit RED, 1 bit Green, 1 bit Blue then it repeats until all 24 bytes are output all on a single pin instead of three
This is incorrect for my cube. What i need is to have 1 byte RED, 1 byte Green, 1 byte Blue then repeat.
So i need this pattern
Panel 0
Col 0-7 which is 1 byte from the RED array
Col 0-7 which is 1 byte from the Green array
Col 0-7 which is 1 byte from the Blue array
then panel 1 and so on