#include <Arduino.h>
const uint8_t LATCH_PIN = 11;  // ST_CP, IC pin 12, copies shifted bits to visible outputs.
const uint8_t CLOCK_PIN = 9;   // SH_CP, IC pin 11, advances the serial shift register.
const uint8_t DATA_PIN = 12;   // DS, IC pin 14, supplies one bit for each clock edge.
uint8_t leds = 0;  // Eight bits remember which LEDs should be on.
void updateShiftRegister() {
  digitalWrite(LATCH_PIN, LOW);
  // LSBFIRST sends bit 0 first; after eight clocks it reaches Q7, not Q0.
  shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, leds);
  digitalWrite(LATCH_PIN, HIGH);  // All outputs change together after the complete byte.
}

void setup() {

  pinMode(LATCH_PIN, OUTPUT); pinMode(DATA_PIN, OUTPUT); pinMode(CLOCK_PIN, OUTPUT);

}
void loop() {
  leds = 0; updateShiftRegister(); delay(100);  // The actual supplied sketch uses 100 ms, not PDF's 500.
  for (uint8_t i = 0; i < 8; ++i) {
    bitSet(leds, i);  // Set one more bit without clearing the LEDs already on.
    updateShiftRegister(); delay(100);
  }
}
