Hello:
I have two Tpic6b595 connected in daisy chain like the image, I have put only four leds to try, Tpic1: leds in Drain0, Drain 1. Tpic2: leds in Drain 0 Drain 1.
The problem is that four leds lights on in 0,1,2 counter and lights two leds at the same time (counter 1), I need to turn on leds individually and in its corresponding position, in this case must light on 0,1 on Tpic1 and 8,9 and Tpic2. It seems that the second Tpic is not working properly.
Can you help me please?
I have using Arduino Mega
and this is the code:
//Pin connected to latch pin
const int latchPin = 9;
//Pin connected to clock pin
const int clockPin = 8;
////Pin connected to Data in
const int dataPin = 7;
int counter = 0;
int numLedsInUse = 16;
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(9600);
Serial.println("*");
// delay a little and then set
delay(100);
}
void loop() {
// Display LED's running
if( counter >= (numLedsInUse-1) ){
counter = 0;
} else {
counter++;
}
Serial.println(counter);
// write to the shift register with the correct bit set high:
registerWrite(counter, HIGH);
delay( 500 );
}
// This method sends bits to the shift register:
void registerWrite(int whichPin, int whichState) {
// the bits you want to send
byte bitsToSend0 = 0;
// write number as bits
bitWrite(bitsToSend0, whichPin, whichState);
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
// shift the bits out
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend0);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}