8×8 LED matrix on an Arduino

I picked a SZ410788K 8×8 LED matrix out of my junk bin today and decided to play around with it. It cost me about 1USD in Aitendo, Akihabara. A little googling brought up the following:

8x8pinout

I decided to hook it up to an Arduino (yea I know, I know).

(more to follow)

Here’s some quick code that scans the matrix:

void setup() {
  // set the digital pin as output:
  pinMode(2, OUTPUT);     
  pinMode(3, OUTPUT);       
  pinMode(3, OUTPUT);       
  pinMode(4, OUTPUT);       
  pinMode(5, OUTPUT);       
  pinMode(6, OUTPUT);       
  pinMode(7, OUTPUT);       
  pinMode(8, OUTPUT);       
  pinMode(9, OUTPUT);       
  pinMode(10, OUTPUT);       
  pinMode(11, OUTPUT);       
  pinMode(12, OUTPUT);       
  pinMode(13, OUTPUT); 
  
  pinMode(A5, OUTPUT);       
  pinMode(A4, OUTPUT);       
  pinMode(A3, OUTPUT);       
  pinMode(A2, OUTPUT);       
  
}

void flash(int x,int y) {
  
   int state1=HIGH;
   int state2=LOW;
   
   for(int n=0;n<2;n++) {
  
   if(n==0) {
     state1=HIGH;
     state2=LOW;
   } else {
     state1=LOW;
     state2=LOW;
   }
   if(x==0) digitalWrite(8, state1); else digitalWrite(8, state2);
   if(x==1) digitalWrite(9, state1); else digitalWrite(9, state2);
   if(x==2) digitalWrite(10, state1); else digitalWrite(10, state2);
   if(x==3) digitalWrite(11, state1); else digitalWrite(11, state2);
   if(x==4) digitalWrite(A5, state1); else digitalWrite(A5, state2);
   if(x==5) digitalWrite(A4, state1); else digitalWrite(A4, state2);
   if(x==6) digitalWrite(A3, state1); else digitalWrite(A3, state2);
   if(x==7) digitalWrite(A2, state1); else digitalWrite(A2, state2);
  
   if(y==0) digitalWrite(12, state1); else digitalWrite(12, state2);
   if(y==1) digitalWrite(13, state1); else digitalWrite(13, state2);
   if(y==2) digitalWrite(2, state1);  else digitalWrite(2, state2);
   if(y==3) digitalWrite(3, state1);  else digitalWrite(3, state2);
   if(y==4) digitalWrite(4, state1);  else digitalWrite(4, state2);
   if(y==5) digitalWrite(5, state1);  else digitalWrite(5, state2);
   if(y==6) digitalWrite(6, state1);  else digitalWrite(6, state2);
   if(y==7) digitalWrite(7, state1);  else digitalWrite(7, state2);
   
   if(n==0) delay(50);
   }
}


void loop()
{

  for(int x=0;x<8;x++) {
    for(int y=0;y<8;y++) {
      flash(x,y);
    }
  }

}

The pins are connected as follows:

Arduino   Matrix
2         K6
3         K5
4         K4
5         K3
6         K2
7         K1
8         K8
9         K7
10        A8 
11        A7
12        A6
13        A5
A5        A4
A4        A3
A3        A2
A2        A1

A 2N3904 is used to switch the grounds in on the A pins. So the circuit looks like this:

8x8diag