shift register

so ive got 2 74hc595 wired up like in the example on the play ground
and im running this code

//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;

char inputString[2];

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("reset");
}

void loop() {
  // iterate over the 16 outputs of the two shift registers
  for (int thisLed = 0; thisLed < 16; thisLed++) {
    // write data to the shift registers:
    registerWrite(thisLed, HIGH);
    // if this is not the first LED, turn off the previous LED:
    if (thisLed > 16) {
      registerWrite(thisLed - 1, HIGH);
    } 
    // if this is  the first LED, turn off the highest LED:
    else {
      registerWrite(0, HIGH);
    } 
    // pause between LEDs:
    delay(250);
  }

}

// This method sends bits to the shift registers:

void registerWrite(int whichPin, int whichState) {
  // the bits you want to send. Use an unsigned int,
  // so you can use all 16 bits:
  unsigned int bitsToSend = 0;    

  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, HIGH);

  // 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 = highByte(bitsToSend);

  // shift the bytes out:
  shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
  shiftOut(dataPin, clockPin, MSBFIRST, registerOne);

  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, LOW);
}

id like each led to light up then turn off, down the line
but instead
each group of 8 leds is doing the pattern
instead of all 16

its like the second shift register
is mimicing the first one

The problem may be the fact that you are setting register one and two to the same value.

  // break the bits into two bytes, one for
  // the first register and one for the second:
  byte registerOne = highByte(bitsToSend);
  byte registerTwo = highByte(bitsToSend);
//? set to the same value ?

Note: You may find it easier to just use a byte per register to store your values instead of a 2 byte unsigned integer. Also, what will you do when you want to run 3 SRs and your function is setup with a hard coded 2 byte param?

You may want to start by just sending B10001010 type values to the shift registers to make sure you have it wired correctly.

Something like this (untested)

void loop() {

  digitalWrite(latchPin, HIGH);

  // shift the bytes out:
  shiftOut(dataPin, clockPin, MSBFIRST, B10010011);
  shiftOut(dataPin, clockPin, MSBFIRST, B10101010);

  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, LOW);

}

You could store the sequence in a an array, like so: int Seq[] = { B1000000000000001, B0100000000000010}; then reference them in a for loop, eg,

for(int i = 0; i < 9; i++)
shiftOut(clockPin, dataPin, latchPin, seq[i]);

Just a note ... B1000000000000001 is not a valid constant. Once you get past B11111111 there are no more predefined constants (at least at 0015 time). Also, there are not 9 entries in the array, so that code would break in the loop.

Sending just two bytes with different values to the shift registers will assure they are wired correctly .. that is job 1.

thanks for your help

so this is the code im running right now

//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);
  Serial.begin(9600);
  Serial.println("reset");
}
void loop() {

  digitalWrite(latchPin, LOW);

  // shift the bytes out:
  shiftOut(dataPin, clockPin, MSBFIRST, B10000001);
  shiftOut(dataPin, clockPin, MSBFIRST, B10000001);

  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);


}

it successfully lights the first and last led connected to each shift register. my question is this,

where would i begin in writing say a led knight rider? in the original code i posted i couldnt get one light to turn on then off down the line

You are sending the same values to the SR's .. so hard to be 100% on the wiring ... if you send the following, which LED lights up?

  // shift the bytes out:
  shiftOut(dataPin, clockPin, MSBFIRST, B01000000);
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);

If only one lights up .. you are good. If 2 light up in the same location, check your wiring. Your reply on which LED lights up will help in your previous question as well.