64 LEDs with 4 TLC5926

I am working on driving a ring of 64 LEDs off of four TLC5926 drivers all powered by the arduino. Eventually I’ll incorporate an encoder to allow midi control with LED feedback.
My setup in 4 TLC5926 chained with SDout → SDin on the next chip.
LE (latch) is connected to D10
CLK (clock) is connected to D13
SDI (serial data in 1st chip) to D11.
These 3 pins are connected in parallel on all 4 chips. The OE (output enable) are all tied low to ground and I have decoupling caps on all V+ near the chips.
I am trying to adapt the following code to shift 16 bit signals through all 64 LEDs and have each led light up individually so it essentially moves around the circular arrangement ive made.

// SPI commands will be used to send the data out


#include <SPI.h> // bring in SPI library

#define SS  10 // output latch for cathodes shift register.  Pin D10 needs to be an output for SPI.

byte dataArray[]= {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};  // load up some initial data
// dataArray[0] = B00000001
// dataArray[1] = B00000010
// dataArray[2] = B00000100
// dataArray[3] = B00001000
// dataArray[4] = B00010000
// dataArray[5] = B00100000
// dataArray[6] = B01000000
// dataArray[7] = B10000000


int x=0;



void setup()
  {

    pinMode (SS, OUTPUT);

    SPI.begin();  // commits 11,12,13 for hardware SPI transfer. Make sure shift registers have 0.1uF/100nF on their VCC pins to ground.
    SPI.setBitOrder(LSBFIRST);
    SPI.setClockDivider(SPI_CLOCK_DIV8);
    SPI.setDataMode(SPI_MODE1);



  }

void loop()
{

  // turn off leds
  digitalWrite (SS, LOW);
  SPI.transfer(0); 
  digitalWrite (SS, HIGH);
  delay(1000);


  for(x=0;x<7;x++)
   {
     // turn on one led, all others off for apox. half a second
     digitalWrite (SS, LOW);
     SPI.transfer(dataArray[x]); 
     digitalWrite (SS, HIGH);
     delay(500);
   
   }

} // end void loop

Im having difficulty understanding how to modify the array for 16 and to utilize the “overflow” principle to shift through the daisy chain. My goal is to first get a single LED moving around the circle, then attach and encoder and having it control the lit LED position on the circle. Thanks!

00000001 (decimal 1) multiplied by 2 equals 00000010 (decimal 2). Another example, 00001100 (decimal 12) multipled by 2 equals 00011000 (decimal 24). In other words, to get the bits to shift to the left you need to multiply them by 2.

The only trick is that when a number is 128 or greater (10000000) that if you multiply it by 2 then the 1 will fall off the end. In your case you have to make sure that if (dataArray(x) >= 128) that dataArray(x + 1) has 1 added to it before multiplying dataArray(x) by 2 so that 1 is not lost.

To make your LEDs spin in the other direction you have to divide the values by 2. To prevent 1's from falling off the end you have to check if (dataArray(x) % 2 == 1).

To combine two 8 bits values into a 16 bit value multiply one by 256 (that's multiplying it by 2 eight times) and add it to the other.

Ok this makes sense to me thanks. I'm having trouble (due to my lack of coding knowledge) how to represent this in the sketch and data array. Ive tried to control just on of the shift registers with the shiftout func but that seems to only support 8bit byte not a 16 bit byte. How do I send the 16 LED states to just on register using spi?

teamskenes:
Ok this makes sense to me thanks. I’m having trouble (due to my lack of coding knowledge) how to represent this in the sketch and data array. Ive tried to control just on of the shift registers with the shiftout func but that seems to only support 8bit byte not a 16 bit byte. How do I send the 16 LED states to just on register using spi?

Just shiftOut() or SPI.transfer() one byte at a time as many times as you need. Shift registers don’t care if you’re sending 8 bits, 5 bits, or 1 bit at a time.

Your code example is a little unperfect; really you should only be pulling the SS pin (or the LE “latch enable” pin, as TI calls it) low once, then shifting out all of your data, then bringing the LE pin high again – “latching” the data:

digitalWrite (SS, LOW);
for(x=0; x<8; x++) {
     shiftOut(dataPin, clockPin, dataArray[x]); 
}
digitalWrite (SS, HIGH);

Note that the SPI library is an interface to the hardware SPI pins and requires you use those pins; it’s like a device driver. The shiftOut() function is a software implementation of SPI. While it’s a little slower (“slow” being measured in millionths of a second) it’s probably what you want to use.