/*
  74HC165 Shift register input example

  https://wokwi.com/arduino/projects/306031380875182657

  (C) 2021, Uri Shaked
*/
const int dataPin = A0;   /* Q7 */
const int clockPin = 3;  /* CP */
const int latchPin = 4;  /* PL */
const int analogData = A1;

const int numBits = 8;   /* Set to 8 * number of shift registers */

void setup() {
  Serial.begin(115200);
  pinMode(dataPin, INPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(analogData, INPUT);
}
void updateShift()
{
  digitalWrite(latchPin, LOW);
  digitalWrite(latchPin, HIGH);
}
void loop() {
  // Step 1: Sample
  digitalWrite(latchPin, LOW);
  digitalWrite(latchPin, HIGH);

  // Step 2: Shift
  Serial.print("Bits: ");
  for (int i = 0; i < numBits; i++) {
    int bit = analogRead(dataPin);
    // if (bit == HIGH) {
      Serial.print(bit);
    // } else {
      Serial.print(",");
    // }
    digitalWrite(clockPin, HIGH); // Shift out the next bit
    digitalWrite(clockPin, LOW);
  }

  Serial.println();
  Serial.println(analogRead(analogData));
  delay(1000);
}
74HC165