I am working on a project to make a worded clock (see picture). I have an array of 10x11 LEDs. All connected with common cathode on one axis, common anode on the other bla bla.
I am using two SN74HC595N shift registers to drive the anodes and two TLC5916IN LED Drivers to drive the cathodes. Yes, I know the 595 is not supposed to drive more than 20mA. So I am scanning along the 595 so only one 595 output is on at a time, it's the TLC5916 that is feeding the multiple outputs. See picture for diagram (please note one difference, I am using one resistor for each TLC for current limit not the shared pot in the diagram).
So, sorry if I gave too much or not enough info. But!! Here's my question, the program (below) is only running the LEDs at 23hz (calculated roughly with a stopwatch) which looks really crap. I assume it's an issue of inefficient code. I have had it running at a nice speed previously when I was not scanning, just leaving all anodes on and changing the cathodes (or the opposite) and that would go plenty quick. I was still using shiftOut to all four registers every cycle, but only two registers had changing values. I'm sorry I can't provide the old working code, I have spent many hours tweaking and fixing and pulling out my hair and didn't think to save copies along the way.
//Worded Clock - Test Pattern
int latchPin = 5; //74H Pin 12 TLC Pin 4 (13 to GND always)
int clockPin = 6; //74H Pin 11 TLC Pin 3
int dataPin = 4; //74H Pin 14 TLC Pin 2
int scan[] = {0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400};
int pat0[] = {0x2AA,0x155,0x2AA,0x155,0x2AA,0x155,0x2AA,0x155,0x2AA,0x155,0x2AA,0x155,0x2AA,0x155,0x2AA,0x155,0x2AA,0x155,0x2AA,0x155,0x2AA};
int hz = 1000;
boolean debug = 0;
int TLC = 0;
int SR = 0;
int sr = 0;
byte reg0 = 0;
byte reg1 = 0;
byte reg2 = 0;
byte reg3 = 0;
unsigned int iteration;
int offset = 0;
int hours;
int minutes;
int seconds;
void setup()
{
if(debug) {
Serial.begin(9600);
Serial.print("TLC (x):");
for(int a=16;a>=0;a--) {
Serial.print(bitRead(TLC,a));
} Serial.println();
Serial.print("SR (y):");
for(int a=16;a>=0;a--) {
Serial.print(bitRead(SR,a));
} Serial.println("////////");
}
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
updateShiftRegister();
}
void loop()
{
sr += 1;
if(sr > 10) {
sr = 0;
}
SR = scan[sr];
for(int i=0;i<10;i++) {
TLC = pat0[sr + offset ];
//delay(1000/hz);
updateShiftRegister();
iteration += 1;
}
if(iteration > 1000) {
iteration = 0;
offset += 1;
if(offset > 1) {
offset = 0;
}
}
}
void updateShiftRegister()
{
//LED Driver Registers
for(int a=8;a<16;a++) {
if(bitRead(TLC, a)) {
bitSet(reg0, -a+15);
}
else {
bitClear(reg0, -a+15);
}
}
for(int a=0;a<8;a++) {
if(bitRead(TLC, a)) {
bitSet(reg1, -a+7);
}
else {
bitClear(reg1, -a+7);
}
}
//Shift Registers
for(int a=8;a<16;a++) {
if(bitRead(SR, a)) {
bitSet(reg2, -a+15);
}
else {
bitClear(reg2, -a+15);
}
}
for(int a=0;a<8;a++) {
if(bitRead(SR, a)) {
bitSet(reg3, -a+7);
}
else {
bitClear(reg3, -a+7);
}
}
if(debug) {
Serial.print("TLC (x):");
for(int a=16;a>=0;a--) {
Serial.print(bitRead(TLC,a));
} Serial.println();
Serial.print("SR (y):");
for(int a=16;a>=0;a--) {
Serial.print(bitRead(SR,a));
} Serial.println();
Serial.print("reg0 (x2):");
for(int a=7;a>=0;a--) {
Serial.print(bitRead(reg0,a));
} Serial.println();
Serial.print("reg1 (x1):");
for(int a=7;a>=0;a--) {
Serial.print(bitRead(reg1,a));
} Serial.println();
Serial.print("reg2 (y2):");
for(int a=7;a>=0;a--) {
Serial.print(bitRead(reg2,a));
} Serial.println();
Serial.print("reg3 (y1):");
for(int a=7;a>=0;a--) {
Serial.print(bitRead(reg3,a));
} Serial.println();
Serial.println("------------------------");
}
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, reg0);
shiftOut(dataPin, clockPin, LSBFIRST, reg1);
shiftOut(dataPin, clockPin, LSBFIRST, reg2);
shiftOut(dataPin, clockPin, LSBFIRST, reg3);
digitalWrite(latchPin, HIGH);
}
Thank you in advance for any help!
-lokthelok