Tal O
Published © LGPL

Never Run Out of Output Pins

HC595 shift register to the rescue!

BeginnerFull instructions provided4,351
Never Run Out of Output Pins

Things used in this project

Story

Read more

Schematics

fritzing_bb_01vVCr7wkV.png

Code

Shifting 2 at a time

Arduino
//Pin connected to ST_CP of 74HC595
int latchPin = D5; //8;
//Pin connected to SH_CP of 74HC595
int clockPin = D6; //12;
////Pin connected to DS of 74HC595
int dataPin = D7; //11;


void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  // count from 0 to 255 and display the number 
  // on the LEDs
  for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
    // take the latchPin low so 
    // the LEDs don't change while you're sending in bits:
    digitalWrite(latchPin, LOW);
    // shift out the bits:
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);  
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);  
    //take the latch pin high so the LEDs will light up:
    digitalWrite(latchPin, HIGH);
    // pause before next value:
    delay(500);
  }
}

Credits

Tal O

Tal O

20 projects • 55 followers
Maker @ heart

Comments