Question about led cube code

So i made a 4x4x4 led cube with 2 shift registers. The cube has 4 layers of 16 led's wich have a common anode, there are also 16 rows with common cathode. I got a code wich works for the opposit, so the layers have common cathode and the rows common anode. But I dont realy know what I have to do in order to let it work properly for my cube. Help would be appreciated. Here is the code :

#define buttonPin 2

unsigned int layer[4] = {0, 0, 0, 0}; //65535 filled layer
byte k = 0;
bool start = true;
unsigned long delayTime;
int speedTime = 0;
int count;

void setup() {
InitializeShiftReg();
InitializeMyLedCube();
}

void InitializeMyLedCube() {
DDRD = B11110000; //pins D0-D3 as INPUTS, D4-D7 as OUTPUTS
PORTD |= B11110000; //turn OFF layers
pinMode(buttonPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(buttonPin), PushButton, FALLING);
delayTime = millis();
}

byte patternNum = 28;
byte pattern = patternNum - 1;

void loop() {
if (start) {
detachInterrupt(digitalPinToInterrupt(buttonPin));
delay(500); //wait for releasing PushButton
pattern++;
if (pattern > patternNum) pattern = 1;
attachInterrupt(digitalPinToInterrupt(buttonPin), PushButton, FALLING);
count = 0;
}
if (((millis() - delayTime) > speedTime) || start) {
switch (pattern) {
case 1: LayersUpDown(); break;
case 2: FallingDot(); break;
case 3: Rain(); break;
case 4: AllCube(); break;
case 5: Cut(); break;
case 6: Cube(); break;
case 7: Diagonal(); break;
case 8: Mixer(); break;
case 9: Random(); break;
case 10: FallingLayer(); break;
case 11: LayerCut(); break;
case 12: Circle(); break;
case 13: RandomWay(); break;
case 14: SmallCube(); break;
case 15: RandomWayCube(); break;
case 16: GrowingCube(); break;
case 17: FallingLayers(); break;
case 18: GrowingLine(); break;
case 19: CircleEdges(); break;
case 20: CircleSide(); break;
case 21: RandomWayLine(); break;
case 22: RandomWaySide(); break;
case 23: DJCube(); break;
case 24: FillingCube(); break;
case 25: NanoBuilding(); break;
case 26: Curve(); break;
case 27: Snake(); break;
case 28: Julka(); break;
default: break;
}
delayTime = millis();
}

//this part displays layers as they are set in functions
SetShiftReg(layer[k]); //send layer data to shift registers
bitClear(PORTD, 4 + k); //turn ON layer k
delay(1); //important for brightness of leds
PORTD |= B11110000; //turn OFF layers
k++; if (k > 3) k = 0; //take another layer in the loop
}

void PushButton() {
start = true;
}

#define latchPin 10 //PORT B2
#define clockPin 9 //PORT B1
#define dataPin 11 //PORT B3
#define resetPin 8 //PORT B0

void InitializeShiftReg() {
DDRB |= B1111; //pins D8-D11 as OUTPUTS
PORTB |= B0001; //resetPin to HIGH
}

void SetShiftReg(unsigned int value) {
bitClear(PORTB, 2); //digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, value >> 8); //shift out high byte, alternative: LSBFIRST / MSBFIRST
shiftOut(dataPin, clockPin, MSBFIRST, value); //shift out low byte, alternative: LSBFIRST / MSBFIRST
bitSet(PORTB, 2); //digitalWrite(latchPin, HIGH);
}

bool direct;
unsigned int actualValue;
byte lay, xVal, yVal;
byte place;

void SetLayers(unsigned int value) {
layer[0] = value; layer[1] = value; layer[2] = value; layer[3] = value;
}

void InversLayers() {
layer[0] = 65535 - layer[0];
layer[1] = 65535 - layer[1];
layer[2] = 65535 - layer[2];
layer[3] = 65535 - layer[3];
}

void ClearLayers() {
SetLayers(0);
}

void LayersUpDown() {
if (start) {
start = false; speedTime = 500;
direct = true;
}
ClearLayers();
layer[count] = 65535;
if (direct) {
count++;
if (count > 3) {
direct = false;
count = 2;
}
} else {
count--; if (count < 1) direct = true;
}
}

void FallingDot() {
if (start) {
start = false; speedTime = 100;
count = 4;
actualValue = 1;
direct = true;
}
count--;
ClearLayers();
layer[count] = actualValue;
if (count == 0) {
count = 4;
actualValue = actualValue << 1;
if (actualValue == 0) actualValue = 1;
}
}

void Rain() {
if (start) {
start = false; speedTime = 200;
ClearLayers();
}
layer[0] = layer[1];
layer[1] = layer[2];
layer[2] = layer[3];
layer[3] = 1 << random(16);
}

void Random() {
if (start) {
start = false; speedTime = 200;
}
layer[0] = random(65536);
layer[1] = random(65536);
layer[2] = random(65536);
layer[3] = random(65536);
}

void AllCube() {
if (start) {
start = false; speedTime = 2000;
}
ClearLayers();
switch (count) {
case 0:
SetLayers(65535);
break;
case 1:
layer[1] = 1632;
layer[2] = 1632;
break;
}
count++; if (count > 1) count = 0;
}

void Cut() {
if (start) {
start = false; speedTime = 2000;
layer[0] = 4369;
layer[1] = 13107;
layer[2] = 30583;
layer[3] = 65535;
}
InversLayers();
}

void Cube() {
if (start) {
start = false; speedTime = 2000;
layer[0] = 15+16+128+256+2048+4096+8192+16384+32768;
layer[1] = 1+8+4096+32768;
layer[2] = layer[1];
layer[3] = layer[0];
}
InversLayers();
}

void Diagonal() {
if (start) {
start = false; speedTime = 2000;
layer[0] = 33825;
layer[1] = 33825;
layer[2] = 33825;
layer[3] = 33825;
}
InversLayers();
}

void Mixer() {
if (start) {
start = false; speedTime = 100;
}
switch (count) {
case 0: actualValue = 33825; break;
case 1: actualValue = 17442; break;
case 2: actualValue = 8772; break;
case 3: actualValue = 4680; break;
case 4: actualValue = 960; break;
case 5: actualValue = 3120; break;
}
SetLayers(actualValue);
count++;
if (count > 5) count = 0;
}

void FallingLayer() {
if (start) {
start = false; speedTime = 100;
actualValue = 0;
direct = false;
}
if (actualValue == 0) {
actualValue = 1;
ClearLayers();
direct = !direct;
layer[3 - (direct? 0:3)] = 65535;
}
switch (count) {
case 0:
layer[3 - (direct? 0:3)] -= actualValue;
layer[2 - (direct? 0:1)] = actualValue;
break;
case 1:
layer[1 + (direct? 0:1)] = layer[2 - (direct? 0:1)];
layer[2 - (direct? 0:1)] = 0;
break;
case 2:
layer[0 + (direct? 0:3)] += layer[1 + (direct? 0:1)];
layer[1 + (direct? 0:1)] = 0;
actualValue = actualValue << 1;
break;
}
count++; if (count > 2) count = 0;
}

void LayerCut() {
if (start) {
start = false; speedTime = 100;
}
if (count) layer[0] = layer[0] << 1;
else layer[0] = 4369;
SetLayers(layer[0]);
count++;
if (count > 20) count = 0;
}

void Circle() {
if (start) {
start = false; speedTime = 100;
lay = 3;
}
switch (count) {
case 0: ClearLayers(); layer[lay] = 1; break;
case 1: layer[lay] = 2; break;
case 2: layer[lay] = 4; break;
case 3: layer[lay] = 8; break;
case 4: layer[lay] = 128; break;
case 5: layer[lay] = 2048; break;
case 6: layer[lay] = 32768; break;
case 7: layer[lay] = 16384; break;
case 8: layer[lay] = 8192; break;
case 9: layer[lay] = 4096; break;
case 10: layer[lay] = 256; break;
case 11: layer[lay] = 16; break;
case 12: layer[lay] = 1; break;
}
count++;
if (count > 12) {
count = 0;
if (lay == 0) lay = 3;
else lay--;
}
}

Help us help you.

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Please post a schematic.

Please post an image of your project.

Please describe the problem better then you just did.

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.