#define latchPin 8 // Pin connected to ST_CP of 74HC595
#define clockPin 12 // Pin connected to SH_CP of 74HC595
#define dataPin 11 // Pin connected to DS of 74HC595

uint16_t data = 0;
uint8_t index = 0;
bool ledState = 1;

void setup() {
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
    for (index = 0; index <= 16; index++) {
      

      bitWrite(data, index, ledState); // led on
      Serial.print("index:"); Serial.print(index);
      Serial.print(", data1:"); Serial.print(data);

      digitalWrite(latchPin, LOW);
      //shiftOut(dataPin, clockPin, MSBFIRST, (data >> 8)); // left to right
      //shiftOut(dataPin, clockPin, MSBFIRST, data); // left to right
      shiftOut(dataPin, clockPin, LSBFIRST, data); // right to left
      shiftOut(dataPin, clockPin, LSBFIRST, (data >> 8)); // right to left
      digitalWrite(latchPin, HIGH);
      ledState = !ledState;
      delay(200);


      bitWrite(data, index, ledState); // led off
      Serial.print(" index:"); Serial.print(index);
      Serial.print(", data0:"); Serial.println(data);

      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, data);
      shiftOut(dataPin, clockPin, MSBFIRST, (data >> 8));
      digitalWrite(latchPin, HIGH);
      ledState = !ledState;
      delay(200);


    }
}
74HC595
74HC595