Thanks for the great link. I've been able to work out a function that will refresh one row at a time. Now if I wanted to control this as an RGB array, and have full color control over each LED, would one LED have to be refreshed at a time, instead of one row at a time? I can't think of another way to do it.
In case anyone is interested, here is the function I came up with. writeMatrix takes 4 parameters. The number of times you want to repeat the pattern, the speed that the pattern will play, the pattern as an array, and the size of the array. This will update a shift register to control the LEDs.
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
//Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;
int squareChase [ ] = {
B00001111,
B00001001,
B00001001,
B00001111,
B00000000,
B00000110,
B00000110,
B00000000
};
int lineChaseH [ ] = {
B00001111,
B00000000,
B00000000,
B00000000,
B00000000,
B00001111,
B00000000,
B00000000,
B00000000,
B00000000,
B00001111,
B00000000,
B00000000,
B00000000,
B00000000,
B00001111
};
int walkPattern [] = {B11100000,
B11010000,
B10110000,
B01110000
};
long int refreshTime = 10; // time in milliseconds between refresh
long int patternRefresh;
int rayCount = 0;
void setup() {
//Set pins for shift register
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
writeMatrix(10,170,lineChaseH,sizeof(lineChaseH)/sizeof(int));
writeMatrix(10,170,squareChase,sizeof(squareChase)/sizeof(int));
} // end of the loop
void writeMatrix(int repetitions, long int patternSpeed, int *patternArray, int raySize) {
repetitionCounter = 0;
while(repetitions > repetitionCounter) {
if(millis() >= patternRefresh){
patternRefresh = millis() + patternSpeed;
rayCount = rayCount + 4;
}
if(rayCount == raySize) {
rayCount = 0;
repetitionCounter++;
}
for(int i = 0; i < 4; i++) {
digitalWrite(latchPin, LOW);
byte byteToSend = patternArray[rayCount + i] | walkPattern[i];
shiftOut(dataPin, clockPin, MSBFIRST, byteToSend);
digitalWrite(latchPin, HIGH);
}
}
}