03-22-2023, 01:02 AM
Code:
/*
* KC868-256 INPUT CODE
74HC165 Shift register input example
*/
const byte latchPin = 33;
const byte clockPin = 32;
const byte dataPin = 15;
const int numBits = 8;
void setup() {
Serial.begin(115200);
pinMode(dataPin, INPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
}
void loop() {
digitalWrite(latchPin, LOW);
digitalWrite(latchPin, HIGH);
for(int j =0;j<=255;j+=8)
{
for (int i = numBits; i >0; i--) {
int bit = digitalRead(dataPin);
if (bit == LOW) {
Serial.printf("Input %d is DOWN\n",i+j);
}
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}
}