Hi,
I need to control 25 led's, one after another. Everything is fine with 2x 595 and 16 leds, but I don't know how to add another 3x 595 and rest of led's :~
When I add third 595 it light up all led's connected to it after last led in second 595.
/*
Created 23 Mar 2010
by Tom Igoe
*/
//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;
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
int bitToSet = 0;
// write to the shift register with the correct bit set high:
for (bitToSet=0; bitToSet<16; bitToSet++){
registerWrite(bitToSet, HIGH);
delay(300);
}
}
// This method sends bits to the shift register:
void registerWrite(int whichPin, int whichState) {
// the bits you want to send
unsigned int bitsToSend = 0;
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
// turn on the next highest bit in bitsToSend:
bitWrite(bitsToSend, whichPin, whichState);
// break the bits into two bytes, one for
// the first register and one for the second:
byte registerOne = highByte(bitsToSend);
byte registerTwo = lowByte(bitsToSend);
// shift the bytes out:
shiftOut(dataPin, clockPin, MSBFIRST, registerOne);
shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}