I'm sorry, I'm not too good with the bits..
I have to say though, if you're looking at using the 595s you HAVE to look at the EarthshineDesign tutorial for them.. explains them the best, and the code they give, is awesome.
http://earthshinedesign.co.uk/ASKManual/Site/ASKManual.html
Click the picture to open the PDF and scroll down..
I don't understand the code.. at all.. and it's still very simple to set it up!
Take a look here, I just use Binary to decide which LED goes on.. for example B10000000 turns on LED number 1, B01000000 turns on the 2nd.. etc etc.. so it's very easy in terms of deciding which LED to turn on, and you're only using 3 pins!
Keep in mind, you can also use multiples as shown, but if so, you need to use shiftOut twice for two.. 3 times for 3.. etc.
Again, I don't understand most of the code at the bottom, but I added my own functions and such.
(Somebody said you can use the >> and <<, to shift the led lit left and right, instead of having to light up each LED by binary, but I haven't figured out how to change the shifted bytes yet)
I hope this helps.. it really seems much easier than using another chip! (but what do I know?:D)
EDIT:
I forgot to mention.. you can call each LED by putting them in an array, like I did below, then using shiftOut(led[2]) to light up the third LED. (remember, arrays begin counting at 0. 0, 1, 2.. you get the point:D)
/* Taken from tutorial by Mike M at EarthshineDesign!
http://earthshinedesign.co.uk/ASKManual/Site/ASKManual.html
*/
// Project 15
//Pin connected to Pin 11 of 74HC595 (Clock)
int clockPin = 9;
//Pin connected to Pin 12 of 74HC595 (Latch)
int latchPin = 10;
//Pin connected to Pin 14 of 74HC595 (Data)
int dataPin = 11;
byte leds[] = {B10000000, B01000000, B00100000, B00010000, B00001000, B00000100, B00000010, B00000001};
void setup() {
//set pins to output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
flashOut(150);
wave(100);
wave(75);
wave(50);
}
void flashIn(int time){
digitalWrite(latchPin, LOW);
shiftOut(B00100100);
digitalWrite(latchPin, HIGH);
delay(time);
digitalWrite(latchPin, LOW);
shiftOut(B00011000);
digitalWrite(latchPin, HIGH);
delay(time);
}
void flashOut(int time){
digitalWrite(latchPin, LOW);
shiftOut(B10000001);
digitalWrite(latchPin, HIGH);
delay(time);
digitalWrite(latchPin, LOW);
shiftOut(B01000010);
digitalWrite(latchPin, HIGH);
delay(time);
digitalWrite(latchPin, LOW);
shiftOut(B11000011);
digitalWrite(latchPin, HIGH);
delay(time);
off(time);
digitalWrite(latchPin, LOW);
shiftOut(B11000011);
digitalWrite(latchPin, HIGH);
delay(time);
off(time);
}
void off(int time){
digitalWrite(latchPin, LOW);
shiftOut(B0);
digitalWrite(latchPin, HIGH);
delay(time);
}
void wave(int time){
digitalWrite(latchPin, LOW);
shiftOut(B10000001);
digitalWrite(latchPin, HIGH);
delay(time);
digitalWrite(latchPin, LOW);
shiftOut(B01000010);
digitalWrite(latchPin, HIGH);
delay(time);
digitalWrite(latchPin, LOW);
shiftOut(B00100100);
digitalWrite(latchPin, HIGH);
delay(time);
digitalWrite(latchPin, LOW);
shiftOut(B00011000);
digitalWrite(latchPin, HIGH);
delay(time);
digitalWrite(latchPin, LOW);
shiftOut(B00100100);
digitalWrite(latchPin, HIGH);
delay(time);
digitalWrite(latchPin, LOW);
shiftOut(B01000010);
digitalWrite(latchPin, HIGH);
delay(time);
digitalWrite(latchPin, LOW);
shiftOut(B10000001);
digitalWrite(latchPin, HIGH);
delay(time);
}
void shiftOut(byte dataOut) {
// Shift out 8 bits LSB first,
// on rising edge of clock
boolean pinState;
//clear shift register ready for sending data
digitalWrite(dataPin, LOW);
digitalWrite(clockPin, LOW);
// for each bit in dataOut send out a bit
for (int i=0; i<=7; i++) {
//set clockPin to LOW prior to sending bit
digitalWrite(clockPin, LOW);
// if the value of DataOut and (logical AND) a bitmask
// are true, set pinState to 1 (HIGH)
if ( dataOut & (1<<i) ) {
pinState = HIGH;
}
else {
pinState = LOW;
}
//sets dataPin to HIGH or LOW depending on pinState
digitalWrite(dataPin, pinState);
//send bit out on rising edge of clock
digitalWrite(clockPin, HIGH);
}
//stop shifting out data
digitalWrite(clockPin, LOW);
}