/*8 Push-Buttons connected to Teensy 4.0 (PIN 4-11),  Array*/ 
/*https://www.youtube.com/watch?v=_biBagZ48Us Götz multiplex*/
#include <Bounce2.h>

const int dataPin = 2;   /* Q7 */
const int clockPin = 3;  /* CP */
const int latchPin = 4;  /* PL */
const int numBits = 8;   /* Set to 8 * number of shift registers */

int bit1 = 0;
int bit2 = 0;
int bit3 = 0;

void setup() {
  Serial.begin(9600);
/*  for ( byte i = 0; i < buttonCnt; i++ ) {
    button[i].attach( buttonPins[i], INPUT_PULLUP );
    button[i].interval(5);   // debounce time
  }*/
  dataPin.attach(dataPin, INPUT_PULLUP );
  pinMode(dataPin, INPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
}

void loop() {
  /*
  for ( byte i = 0; i < buttonCnt; i++ )   button[i].update();

  for ( byte i = 0; i < buttonCnt; i++ ) {
    if (button[i].fallingEdge()) {
      Serial.print("Button "); Serial.print(i); Serial.println(" was pressed");
    }
    if (button[i].risingEdge()) {
      Serial.print("Button "); Serial.print(i); Serial.println(" was released");
    }
  }
  */
  // Step 1: Sample
  
  digitalWrite(latchPin, LOW);
  digitalWrite(latchPin, HIGH);

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

  Serial.println();
  delay(100);
  
  
}
74HC165
74HC165