int D0 = 0; // PD0 int D1 = 1; // PD1 int D2 = 2; // PD2 int D3 = 3; // PD3 data Poorten int D4 = 4; // PD4 int D5 = 5; // PD5 int D6 = 6; // PD6 int D7 = 7; // PD7 int Yselect =A0; // C0 activates the selected layer int Adr0 = A1; // C1 addres for columns int Adr1 = A2; // C2 int Adr2 = A3; // C3 int enable = A4; // C4 activates columns byte LED [8][8]= { {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, };; // array of LED's 8 layers , 8 columns = 8x8x8; byte poort = B11111111; byte x,y = 0; void setup () { pinMode(D0, OUTPUT); pinMode(D1, OUTPUT); pinMode(D2, OUTPUT); pinMode(D3, OUTPUT); pinMode(D4, OUTPUT); pinMode(D5, OUTPUT); pinMode(D6, OUTPUT); pinMode(D7, OUTPUT); pinMode(Yselect, OUTPUT); pinMode(Adr0, OUTPUT); pinMode(Adr1, OUTPUT); pinMode(Adr2, OUTPUT); pinMode(enable, OUTPUT); } void loop (){ digitalWrite(enable,HIGH); writecube(); x = 0;y=0; while (x != 8) { while (y!=8) { LED[x][y]=255; y++; } y=0; x++; } writecube(); clearcube(); // alle leds uit writecube(); x = 0;y=0; while (x != 8) { LED[x][x]=255; x++; } writecube(); clearcube(); // alle leds uit x = 0;y=7; while (x != 8) { LED[x][y]=255; x++;y--; } writecube(); clearcube(); // alle leds uit x = 0;y=7; //een kruis while (x != 8) { LED[x][y]=255; x++;y--; } x = 0;y=0; while (x != 8) { LED[x][x]=255; x++; } writecube(); clearcube(); // alle leds uit x = 0;y=0; while (y !=8) { while (x !=8) // een vertikale op positie 0 {LED [x][y]=1; x++; } writecubefast(); x=0;y++;} x = 0;y=0; while (y !=8) { while (x !=8) // een vertikale op positie 0 {LED [x][y]=2; x++; } writecubefast(); x=0;y++;} x = 0;y=0; while (y !=8) { while (x !=8) // een vertikale op positie 0 {LED [x][y]=4; x++; } writecubefast(); x=0;y++;} x = 0;y=0; while (y !=8) { while (x !=8) // een vertikale op positie 0 {LED [x][y]=8; x++; } writecubefast(); x=0;y++;} x = 0;y=0; while (y !=8) { while (x !=8) // een vertikale op positie 0 {LED [x][y]=16; x++; } writecubefast(); x=0;y++;} x = 0;y=0; while (y !=8) { while (x !=8) // een vertikale op positie 0 {LED [x][y]=32; x++; } writecubefast(); x=0;y++;} x = 0;y=0; while (y !=8) { while (x !=8) // een vertikale op positie 0 {LED [x][y]=64; x++; } writecubefast(); x=0;y++;} x = 0;y=0; while (y !=8) { while (x !=8) // een vertikale op positie 0 {LED [x][y]=128; x++; } writecubefast(); x=0;y++;} } void writecube (){byte counter =0; while (counter!=20) {writecubeonce(); ++counter;} } void writecubefast (){byte counter =0; while (counter!=2) {writecubeonce(); ++counter;} } void writecubeonce(){byte layer = 0; while (layer !=8) { PORTD = B11111111; digitalWrite(Yselect,LOW); // aktiveer laag digitalWrite(Yselect,HIGH); writelayer(layer); if (layer==0) {PORTD = B11111110;}; // onderste laag selekteren if (layer==1) {PORTD = B11111101;}; if (layer==2) {PORTD = B11111011;}; if (layer==3) {PORTD = B11110111;}; if (layer==4) {PORTD = B11101111;}; if (layer==5) {PORTD = B11011111;}; if (layer==6) {PORTD = B10111111;}; if (layer==7) {PORTD = B01111111;}; //bovenste laag selekteren // digitalWrite(Yselect,HIGH); digitalWrite(Yselect,LOW); // aktiveer laag digitalWrite(Yselect,HIGH); delay (2); layer++; } } void writelayer (byte layer1){ byte line = 0; // complete laag schrijven while (line != 8) { writeline (layer1,line); line++; } } void writeline (byte layer2, byte line2){ // laagste nivo schrijf de bit naar buiten layer en line worden gebruikt byte line1; line1 = line2 <<1; // line = poort C1,C2,C3 XXXXBBBX B=bitje line1 = line1 & B00001110; // voor de zekerheid alleen deze 3 bits PORTC = PORTC & B11110001; // bitjes C1,C2,C3 clear PORTC = PORTC | line1; // bitje C1,C2,C3 naar buiten PORTD = LED [layer2][line2]; // 8 x bitje naar buiten PORTD = PORTD ^ B11111111; // inverteren digitalWrite(enable,LOW); // data wordt in de d-latches geklokt digitalWrite(enable,HIGH); // en weer terug hoog } void clearcube() // deze routine doet alle leds uit { x = 0;y=0; while (x != 8) // tel van 0 tot 7 { while (y!=8) // tel van 0 tot 7 { LED[x][y]=0; // het gehele array wordt = 0 y++; } y=0; x++; } }