Go Down

Topic: 74HC595: Getting code for 4 daisy chained 74HC595 to work (Read 641 times) previous topic - next topic

flocked

Hi,

I try to getting my code for 4 daisy chained 74HC595 to work.  The attached functions is for two 74HC595. I know that I need to shiftout 4 times, but what else do I need to change in the function? How can I split the whichPin integer into 4 bytes.

Thanks!

Code: [Select]
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, 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, registerTwo);
  shiftOut(dataPin, clockPin, MSBFIRST, registerOne);

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

guix



Go Up