just wanted to say good job on all your work put into this. Keep it up
Ryan
;D
Thanks, the project forked into something else quite a number of months ago but was useful for putting the 595 through its paces, now I look back on the code, it's really quite hard to follow.
So it's important to read this tutorial first:
http://www.arduino.cc/en/Tutorial/ShftOut22
There's code examples that explain how to start off with 1 register, then 2.
The key to lighting up all 16 LEDs, while really only having 8 on at a time, is this loop:
digitalWrite(latchPin, 0); // ground the latchpin
shiftOut(dataPin, clockPin, 255); // 1st register ignite all 8 LEDs
shiftOut(dataPin, clockPin, 0); // 2nd register turns off all 8 LEDs
digitalWrite(latchPin, 1); // return the latch pin high
digitalWrite(latchPin, 0); // ground the latchpin
shiftOut(dataPin, clockPin, 0); // 1st register turns off all 8 LEDs
shiftOut(dataPin, clockPin, 255); // 2nd register ignite all 8 LEDs
digitalWrite(latchPin, 1); // return the latch pin high
Because of the speed, the human eye will only see 16 LEDs turned on, while really there is only power going to 8 LEDs. Adding extra 595's to expand on the number of LEDs, while still only having 8 LEDs powered at any one time (thus not blowing up the Arduino), is done per:
digitalWrite(latchPin, 0); // ground the latchpin
shiftOut(dataPin, clockPin, 255); // 8 on
shiftOut(dataPin, clockPin, 0); // 8 off
shiftOut(dataPin, clockPin, 0); // 8 off
shiftOut(dataPin, clockPin, 0); // 8 off
digitalWrite(latchPin, 1); // return the latch pin high
digitalWrite(latchPin, 0); // ground the latchpin
shiftOut(dataPin, clockPin, 0); // 8 off
shiftOut(dataPin, clockPin, 255); // 8 on
shiftOut(dataPin, clockPin, 0); // 8 off
shiftOut(dataPin, clockPin, 0); // 8 off
digitalWrite(latchPin, 1); // return the latch pin high
digitalWrite(latchPin, 0); // ground the latchpin
shiftOut(dataPin, clockPin, 0); // 8 off
shiftOut(dataPin, clockPin, 0); // 8 off
shiftOut(dataPin, clockPin, 255); // 8 on
shiftOut(dataPin, clockPin, 0); // 8 off
digitalWrite(latchPin, 1); // return the latch pin high
digitalWrite(latchPin, 0); // ground the latchpin
shiftOut(dataPin, clockPin, 0); // 8 off
shiftOut(dataPin, clockPin, 0); // 8 off
shiftOut(dataPin, clockPin, 0); // 8 off
shiftOut(dataPin, clockPin, 255); // 8 on
digitalWrite(latchPin, 1); // return the latch pin high
You can downsize this code using variables and counters.
I had 8 595's wired up to ultra high powered LEDs and this worked fine, I don't think there's a limit to the number of 595's you can piggy-back, so for cost its an economic solution to controlling large numbers of LEDs, you can buy 10 off a number of eBay sellers for just a few bucks