Using a Shift Register

The Shift Register

The breakout uses a very common shift register, the 74LS595D. To drive 16 Led you need two of them as each of them can only drive 8 Leds. The shift register is latched, which means that the data is shifted into the register but displayed only when the latch is cleared. This avoids a flickering when writing the data.

There are many articles on this shift register so we will not dive into its operation.


We connect the shift register to the left side of the HelvePic32:

int enPin = nP[LEFT][3];  // Shift registers' Output Enable pin
int latchPin = nP[LEFT][4];  // Shift registers' rclk pin
int clkPin = nP[LEFT][5];  // Shift registers' srclk pin
int clrPin = nP[LEFT][6];  // shift registers' srclr pin
int datPin = nP[LEFT][7];  // shift registers' SER pin

Any data we want to write to the shift register will be pushed into the register through a shiftOut function

void shiftOut16(uint16_t data)
{
        byte datamsb;
        byte datalsb;

        datamsb = (data&0xFF00)>>8;  // mask out the MSB and shift it right 8 bits
        datalsb = data & 0xFF;  // Mask out the LSB

        Serial.print("  ");
        Serial.print(datamsb,DEC);
        Serial.print("  ");
        Serial.print(datalsb,DEC);

        digitalWrite(latchPin, LOW);  // first send latch low
        shiftOut(datPin, clkPin, MSBFIRST, datamsb);
        shiftOut(datPin, clkPin, MSBFIRST, datalsb);
        digitalWrite(latchPin, HIGH);  // send latch high to indicate data is done sending
}