Thank you for the feedback. Here is the compiled code as it is running on the Arduino. I hope there are enough comments in there to answer any questions.
Again, calling the function from the for loop works great, when calling from any other place i am unable to get the LEDs to light.
//Set up 74hc595
//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
//This is the code for the 74hc595
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
//Setup the Serial Connection
Serial.begin(9600);
Serial.println("reset");
}
void loop() {
// This works in lighting up the LEDs in sequence, one at a time
for ( int bitToSet = 0; bitToSet <=8; bitToSet++ ) {
registerWrite(bitToSet, HIGH);
Serial.println(bitToSet);
delay(1000);
}
//Light up LED "3"
// This does not work
registerWrite(3, HIGH);
Serial.println("set bit 3 ON");
delay(1000);
//Light up LED 5
// This should turn off the non-lit 3 and turn on 5
// This also does nothing
registerWrite(5, HIGH);
Serial.println("set bit 5 ON");
delay(1000);
} // End Loop
void registerWrite(int whichPin, int whichState) {
Serial.print("called registerWrite PIN - ");
Serial.println(whichPin);
byte bitsToSend = 0;
// turn off the output so the pins don't light up
digitalWrite(latchPin, LOW);
// turn on the next highest bit in bitsToSend:
bitWrite(bitsToSend, whichPin, whichState);
Serial.print("bitsToSend - ");
Serial.println(bitsToSend);
// shift the bits out:
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}
Once this understand why this is happening, I am hoping that I can re-write the function to turn on multiple bits at the same time. But, that is something for another post or day.
Thanks again, Josh