OK I have been trying to get an RGB LED Matrix running using the TLC5940 but as I only had 2 chips and really need 3 to multipliex an 8x8 array I thought of using a 595 shift register to control the common anode rows instead. With two TLC5940's I can then multiplex the 3 colours.
However, for some weird reason the column data gets carried down into the row below despite turning the row above off before displaying the next one. If I have a long delay inbetween rows it works fine but if I reduce the delay to a toy one I get the bleedover.
Here is some test code just to get the rows showing something different, but I am getting the column data showing up on the next row as well as on the one it is supposed to show on. Can anyone tell me why please :-
#include "tlc_config.h"
#include "Tlc5940.h"
//Pin connected to ST_CP of 74HC595
int latchPin = 2;
//Pin connected to SH_CP of 74HC595
int clockPin = 5;
////Pin connected to DS of 74HC595
int dataPin = 4;
void setup()
{
/* Tlc.init() has to be called before using any of the library functions */
Tlc.init();
pinMode(latchPin, OUTPUT);
}
void loop()
{
/*
* Tlc.set(channel (0-15), value (0-4095)) sets the grayscale value for
* one channel (15 is OUT15 on the first TLC, if multiple TLCs are daisy-
* chained, then channel = 16 would be OUT0 of the second TLC, etc.).
*
* value goes from off (0) to always on (4095).
*/
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, B10000000);
Tlc.clear();
Tlc.set(0, 2095);
Tlc.set(1, 2095);
Tlc.set(2, 2095);
Tlc.set(3, 2095);
Tlc.set(12, 2095);
Tlc.set(13, 2095);
Tlc.set(14, 2095);
Tlc.set(15, 2095);
Tlc.update();
digitalWrite(latchPin, 1);
delay(2);
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, B01000000);
Tlc.clear();
Tlc.set(0, 2095);
digitalWrite(latchPin, 1);
Tlc.update();
delay(2);
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, B00100000);
Tlc.clear();
Tlc.set(1, 2095);
Tlc.update();
digitalWrite(latchPin, 1);
delay(2);
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, B00010000);
Tlc.clear();
Tlc.set(2, 2095);
Tlc.update();
digitalWrite(latchPin, 1);
delay(2);
}
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut[ch65533]
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}