how to use SPI led matrix?

I found an Led matrix claiming to be an SPI device but i cant figure out how to use the serial interface, I have it working, but not very well. Can anyone figure out how to use this?

here is the datasheet http://exdwh.com/LT1450ED.pdf

this is my current code:

void updateDisp(){
   for(int x=0;x<16;x++){
        for(int y=0;y<16;y++){
        row(x);
        digitalWrite(red, gridR[x][y]);
        digitalWrite(green, gridG[x][y]);
        digitalWrite(clock, HIGH);
        digitalWrite(clock, LOW);
        
   }
  digitalWrite(enable,LOW);
  delay(1);
  digitalWrite(latch,LOW);
  digitalWrite(latch,HIGH);
  digitalWrite(enable,HIGH);  
 }
 }
 
 void row(int row){
   
   switch(row){
     case (0):digitalWrite(a1, LOW);digitalWrite(a2, LOW);digitalWrite(a3, LOW);digitalWrite(a4, LOW);
       break;  
     case (1):digitalWrite(a1, HIGH);digitalWrite(a2, LOW);digitalWrite(a3, LOW);digitalWrite(a4, LOW);
       break;
     case (2):digitalWrite(a1, LOW);digitalWrite(a2, HIGH);digitalWrite(a3, LOW);digitalWrite(a4, LOW);
       break;
     case (3):digitalWrite(a1, HIGH);digitalWrite(a2, HIGH);digitalWrite(a3, LOW);digitalWrite(a4, LOW);
       break;
     case (4):digitalWrite(a1, LOW);digitalWrite(a2, LOW);digitalWrite(a3, HIGH);digitalWrite(a4, LOW);
       break;
     case (5):digitalWrite(a1, HIGH);digitalWrite(a2, LOW);digitalWrite(a3, HIGH);digitalWrite(a4, LOW);
       break;
     case (6):digitalWrite(a1, LOW);digitalWrite(a2, HIGH);digitalWrite(a3, HIGH);digitalWrite(a4, LOW);
       break;
     case (7):digitalWrite(a1, HIGH);digitalWrite(a2, HIGH);digitalWrite(a3, HIGH);digitalWrite(a4, LOW);
       break;
     case (8):digitalWrite(a1, LOW);digitalWrite(a2, LOW);digitalWrite(a3, LOW);digitalWrite(a4, HIGH);
       break;
     case (9):digitalWrite(a1, HIGH);digitalWrite(a2, LOW);digitalWrite(a3, LOW);digitalWrite(a4, HIGH);
       break;
     case (10):digitalWrite(a1, LOW);digitalWrite(a2, HIGH);digitalWrite(a3, LOW);digitalWrite(a4, HIGH);
       break;
     case (11):digitalWrite(a1, HIGH);digitalWrite(a2, HIGH);digitalWrite(a3, LOW);digitalWrite(a4, HIGH);
       break;
     case (12):digitalWrite(a1, LOW);digitalWrite(a2, LOW);digitalWrite(a3, HIGH);digitalWrite(a4, HIGH);
       break;
     case (13):digitalWrite(a1, HIGH);digitalWrite(a2, LOW);digitalWrite(a3, HIGH);digitalWrite(a4, HIGH);
       break;
     case (14):digitalWrite(a1, LOW);digitalWrite(a2, HIGH);digitalWrite(a3, HIGH);digitalWrite(a4, HIGH);
       break;
     case (15):digitalWrite(a1, HIGH);digitalWrite(a2, HIGH);digitalWrite(a3, HIGH);digitalWrite(a4, HIGH);
       break;
     }
   }

So, what does it do (with your code), what does it not do, and what do you expect it to do?

transistor77777:
I have it working, but not very well.

Hi,

  1. You are calling your row() function for each bit of data you are clocking in (i.e. it is inside the inner for loop). You should do this only after you have clocked in all 16 bits of the red and green data, i.e. in the outer for loop.

  2. Your delay() should also be in the outer for loop, after the call to row(). Enable the shift register outputs just before the delay, then disable them again just after the delay, to avoid “bleed” into the next column.

  3. your row() function could be much shorter, easier to read and faster - check out the bitRead() function.

Try something like this:

void updateDisp() {
   for(int x=0;x<16;x++) {
     for(int y=0;y<16;y++) {
        digitalWrite(red, gridR[x][y]);
        digitalWrite(green, gridG[x][y]);
        digitalWrite(clock, HIGH);
        digitalWrite(clock, LOW);
      }
    digitalWrite(latch,LOW);
    digitalWrite(latch,HIGH);
    row(x);
    digitalWrite(enable,LOW);
    delay(1);
    digitalWrite(enable,HIGH);  
  }
}

const byte adrsPin[4] = {a1, a2, a3, a4};
 
void row(byte row) {
  for (byte a=0;a<4;a++) {
    digitalWrite(adrsPin[a], bitRead(row, a));
  }
}

Paul