Smart Home Automation Forum
[Arduino source code for KC868-A256]-02 INPUT_256 - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KC868-A256 (https://www.kincony.com/forum/forumdisplay.php?fid=44)
+--- Thread: [Arduino source code for KC868-A256]-02 INPUT_256 (/showthread.php?tid=2717)



[Arduino source code for KC868-A256]-02 INPUT_256 - KinCony Support - 03-22-2023

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);
  }
  }
}