Smart Home Automation Forum
[Arduino source code for KC868-A8M]-03 INPUT - 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-A8M (https://www.kincony.com/forum/forumdisplay.php?fid=48)
+--- Thread: [Arduino source code for KC868-A8M]-03 INPUT (/showthread.php?tid=2800)



[Arduino source code for KC868-A8M]-03 INPUT - KinCony Support - 04-14-2023

Code:
/*KC868-A8M input trigger output*/
#include "Arduino.h"
#include "PCF8574.h"

#define SDA 5
#define SCL 4
// Set i2c address
PCF8574 pcf8574_IN1(0x22,SDA,SCL);
PCF8574 pcf8574_RE(0x24,SDA,SCL);
unsigned long timeElapsed;
void setup()
{
    Serial.begin(115200);
    delay(1000);
    pcf8574_RE.pinMode(P0, OUTPUT);
    pcf8574_RE.pinMode(P1, OUTPUT);
    pcf8574_RE.pinMode(P2, OUTPUT);
    pcf8574_RE.pinMode(P3, OUTPUT);
    pcf8574_RE.pinMode(P4, OUTPUT);
    pcf8574_RE.pinMode(P5, OUTPUT);
    pcf8574_RE.pinMode(P6, OUTPUT);
    pcf8574_RE.pinMode(P7, OUTPUT);
   
    pcf8574_IN1.pinMode(P0, INPUT);
    pcf8574_IN1.pinMode(P1, INPUT);
    pcf8574_IN1.pinMode(P2, INPUT);
    pcf8574_IN1.pinMode(P3, INPUT);
    pcf8574_IN1.pinMode(P4, INPUT);
    pcf8574_IN1.pinMode(P5, INPUT);
    pcf8574_IN1.pinMode(P6, INPUT);
    pcf8574_IN1.pinMode(P7, INPUT);
    pcf8574_IN1.begin();
    pcf8574_RE.begin();
}

void loop()
{
uint8_t val1 = pcf8574_IN1.digitalRead(P0);
uint8_t val2 = pcf8574_IN1.digitalRead(P1);
uint8_t val3 = pcf8574_IN1.digitalRead(P2);
uint8_t val4 = pcf8574_IN1.digitalRead(P3);
uint8_t val5 = pcf8574_IN1.digitalRead(P4);
uint8_t val6 = pcf8574_IN1.digitalRead(P5);
uint8_t val7 = pcf8574_IN1.digitalRead(P6);
uint8_t val8 = pcf8574_IN1.digitalRead(P7);
if (val1==LOW) {
  pcf8574_RE.digitalWrite(P0,LOW);
  delay(100);
  }
else pcf8574_RE.digitalWrite(P0,HIGH);
if (val2==LOW) {
  pcf8574_RE.digitalWrite(P1,LOW);
  delay(100);
  }
else pcf8574_RE.digitalWrite(P1,HIGH);
if (val3==LOW)  {
  pcf8574_RE.digitalWrite(P2,LOW);
  delay(100);
  }
else pcf8574_RE.digitalWrite(P2,HIGH);
if (val4==LOW)  {
  pcf8574_RE.digitalWrite(P3,LOW);
  delay(100);
  }
else pcf8574_RE.digitalWrite(P3,HIGH);
if (val5==LOW)  {
  pcf8574_RE.digitalWrite(P4,LOW);
  delay(100);
  }
else pcf8574_RE.digitalWrite(P4,HIGH);
if (val6==LOW)  {
  pcf8574_RE.digitalWrite(P5,LOW);
  delay(100);
  }
else pcf8574_RE.digitalWrite(P5,HIGH);
if (val7==LOW)  {
  pcf8574_RE.digitalWrite(P6,LOW);
  delay(100);
  }
else pcf8574_RE.digitalWrite(P6,HIGH);
if (val8==LOW)  {
  pcf8574_RE.digitalWrite(P7,LOW);
  delay(100);
  }
else pcf8574_RE.digitalWrite(P7,HIGH);

    delay(300);
}
[Arduino source code for KC868-A8M]-03 INPUT