In the LEControl.CPP file you will see it is using shiftOut, which is very slow. You should be able to change that to use either direct port manipulation or better yet - SPI.
Here is the place in code that looks like it would need to be updated.void LedControl::spiTransfer(int addr, volatile byte opcode, volatile byte data) {
//Create an array with the data to shift out
int offset=addr*2;
int maxbytes=maxDevices*2;
for(int i=0;i<maxbytes;i++)
spidata[i]=(byte)0;
//put our device data into the array
spidata[offset+1]=opcode;
spidata[offset]=data;
//enable the line
digitalWrite(SPI_CS,LOW);
//Now shift out the data
for(int i=maxbytes;i>0;i--)
shiftOut(SPI_MOSI,SPI_CLK,MSBFIRST,spidata[i-1]);
//latch the data onto the display
digitalWrite(SPI_CS,HIGH);
}
If the one line in the above code is changed from ..
shiftOut(SPI_MOSI,SPI_CLK,MSBFIRST,spidata[i-1]);
to use either shiftOutFast or spi_transfer in the below post you may find speed improvements. This post was me learning the same thing and providing the results. If you hit issues or have questions attempting to implement this I'll jump in an help.
http://arduino.cc/forum/index.php/topic,37304.0.htmlTo use this code you may need to update your pins to 10 - latch - 13 clock and data 11.
Since there is a tone of code in that post - here are the important parts (may have missed something but this is a good start).
//--- vars
//--- Pin connected to ST_CP of 74HC595
int latchPin = 10;
//--- Pin connected to SH_CP of 74HC595
int clockPin = 13;
//--- Pin connected to DS of 74HC595
int dataPin = 11;
//--- Used for faster latching
int latchPinPORTB = latchPin - 8;
//----- Setup()
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
digitalWrite(latchPin,LOW);
digitalWrite(dataPin,LOW);
digitalWrite(clockPin,LOW);
//--CMD SerialCommander.initialize(runCommands);
setupSPI();
//----- Other routines
void latchOn(){
bitSet(PORTB,latchPinPORTB);
}
void latchOff(){
bitClear(PORTB,latchPinPORTB);
}
void setupSPI(){
byte clr;
SPCR |= ( (1<<SPE) | (1<<MSTR) ); // enable SPI as master
//SPCR |= ( (1<<SPR1) | (1<<SPR0) ); // set prescaler bits
SPCR &= ~( (1<<SPR1) | (1<<SPR0) ); // clear prescaler bits
clr=SPSR; // clear SPI status reg
clr=SPDR; // clear SPI data reg
SPSR |= (1<<SPI2X); // set prescaler bits
//SPSR &= ~(1<<SPI2X); // clear prescaler bits
delay(10);
}
byte spi_transfer(byte data)
{
SPDR = data; // Start the transmission
loop_until_bit_is_set(SPSR, SPIF);
return SPDR; // return the received byte, we don't need that
}
If you implement the above code - then use the spi_transfer method in place of the line detailed above .. so ...
shiftOut(SPI_MOSI,SPI_CLK,MSBFIRST,spidata[i-1]);
is changed to
spi_transfer(spidata[i-1]);
That may do it, best of luck - let us know please. Here to help if you hit snags.