My question is how to write code to manage layers using the 74HC595?
Here we assume the code in which the layers are connected to the Arduino and I have to manage layers using the 74HC595
int data = 4; // HC595-1, 2
int clock = 5; // HC595-1, 2
int latch = 6; // HC595-1, 2
int layerPin[] = {
7,8,9,10};
int data8x8[] = {
0, 0, 0, 0, 0, 0, 0, 0}
;
void setup(){
Serial.begin(9600);
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
for (int i = 0; i < 4; i ++){
pinMode(layerPin[i], OUTPUT);
}
}
void loop(){
for (int z = 0; z < 4; z++){
for (int y = 0; y < 4; y++){
for (int x = 0; x < 4; x++){
int xbijy= y*4 + x;
int shiftReg = z*2+ xbijy / 8;
int bitNr = xbijy % 8;
data8x8[shiftReg] = 1<<bitNr;
drawCube(100);
}
}
}
}
void drawCube(int duur){
for (int t = 0; t < duur; t++){
for (int zz=0; zz < 4; zz++){
digitalWrite(latch,LOW);
shiftOut(data, clock, LSBFIRST, data8x8[zz*2]);
shiftOut(data, clock, LSBFIRST, data8x8[zz*2 + 1]);
digitalWrite(latch,HIGH);
}
}
}