Try this Pedro. Not debugged, should be pretty close.
Some might suggest burying stuff in functions, I say skip that and just let it run fast!
// code to read data from an 8 byte array and display on 8x8 LED matrix with shift registers and current limit resistors driving anodes,
// and shift register with high current drivers sinking common cathodes.
// SPI commands will be used to send the data out
// sequence: every xx milliseconds, turn off all cathodes
// set up anodes from data stored in an array
// turn on next cathode
//
// while time is passing for the next set of anodes, do other stuff
// repeat
#include <SPI.h> // bring in SPI library
byte SSanodes = 9; // output latch for anodes shift register. Can be any pin except 10,11,12,13.
byte SScathodes = 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
byte cathodePins[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; // used to turn on 1 cathode at a time
unsigned long timeNow = 0; // capture time
unsigned long previousTime = 0; // store previous time
unsigned long elapsedTime = 5; // time that each column will be on
byte anodeColumn = 0; // keep track of column being driven
void setup(){
pinMode (SSanodes, OUTPUT);
pinMode (SScathodes, 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.
}
void loop(){
timeNow = millis(); // capture the current 'time'
if ((timeNow - previousTime)>= elapsedTime){ // display refresh time?
previousTime = previousTime + elapsedTime; //setup for next pass
// keep track of which column is being written
anodeColumn = anodeColumn+1;
if (anodeColumn == 8){anodeColumn = 0;} // reset after going 0,1,2,3,4,5,6,7 >> 0
// turn off current cathode
digitalWrite (SScathodes, LOW);
SPI.transfer(0); // 0 = all cathode off >> assumes HC595 driving base of NPN transistor or ULN2803
digitalWrite (SScathodes, HIGH);
// shift out next set of anodes
digitalWrite (SSanodes, LOW);
SPI.transfer(dataArray[anodeColumn]); // read data from the array and send it out
digitalWrite (SSanodes, HIGH);
// turn the next cathode on
digitalWrite (SScathodes, LOW);
SPI.transfer(cathodePins[anodeColumn]); // 0 = all cathode off >> assumes HC595 driving base of NPN transistor or ULN2803
digitalWrite (SScathodes, HIGH);
} // end of time check
// make sure that all compiles & runs okay. If too flickery, decrease elapsedTime. Maybe even go to micros() instead of millis();
// next, add your code to read buttons, receive serial data, whatever your method for making updates to dataArray[x]
// for example, this should move the On LED in each row across the screen every 1/2 second
/* add variable definitions as above
// timeNow already captured at the top of void loop
if ( (timeNow - previousShiftTime)>= elapsedShiftTime){
previousShiftTime = previousShiftTime + elapsedShiftTime;
tempArray = arrayData[0]; // store column 0
arrayData[0] = arrayData[1]; // column 0 becomes column 1
arrayData[1] = arrayData[2]; // 1 becomes 2
arrayData[2] = arrayData[3];
arrayData[3] = arrayData[4];
arrayData[4] = arrayData[5];
arrayData[5] = arrayData[6];
arrayData[6] = arrayData[7];
arrayData[7] = tempArray; // finally 7 becomes what 0 was.
}
*/
// display will show the new data at the next display update interval
} // end void loop