/*
A small test of inputting from a 74HC165 PISO Shift Register.
*/
const int dataPin = 2; /* Q7 */
const int clockPin = 3; /* CP */
const int latchPin = 4; /* PL */
const int cePin = 13; /* CE */
byte incomingBits;
byte prevBits;
void setup() {
Serial.begin(9600);
pinMode(dataPin, INPUT_PULLUP);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(cePin, OUTPUT);
digitalWrite(cePin, LOW);
}
void loop() {
digitalWrite(latchPin, LOW);
digitalWrite(latchPin, HIGH);
digitalWrite(clockPin, HIGH);
digitalWrite(cePin, LOW);
byte incomingBits = shiftIn(dataPin, clockPin, LSBFIRST);
digitalWrite(cePin, HIGH);
if(incomingBits != prevBits) {
Serial.println("Bits are: ");
for(int i = 0; i < 8;i++) {
Serial.print(bitRead(incomingBits,i), BIN);
}
Serial.println();
prevBits = incomingBits;
}
delay(10);
}