Smart Home Automation Forum
[Arduino IDE demo source code for KC868-E16S]--#03-KC868-E16S-8574-DO - 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-E16S/E16P (https://www.kincony.com/forum/forumdisplay.php?fid=26)
+--- Thread: [Arduino IDE demo source code for KC868-E16S]--#03-KC868-E16S-8574-DO (/showthread.php?tid=1925)



[Arduino IDE demo source code for KC868-E16S]--#03-KC868-E16S-8574-DO - KinCony Support - 05-17-2022

[Arduino IDE demo source code for KC868-E16S]--#03-KC868-E16S-8574-DO
   

Code:
/*KC868-E16S Code of PCF8574 OUTPUT  CONTROL RELAYS*/
/*Press and hold on key Download ,relays ON,   release key relays OFF*/
#include "Arduino.h"
#include "PCF8574.h"

/*Set pcf8574 Output i2c address and SDA IO16/ SCL IO15*/
#define buttonPin 0
PCF8574 pcf8574_1(0x21,16,15);
PCF8574 pcf8574_2(0x25,16,15);

void setup()
{
    Serial.begin(115200);
/* Set pinMode to OUTPUT*/
   pinMode(buttonPin, INPUT);// key download  IO0

    pcf8574_1.pinMode(P0, OUTPUT);
  pcf8574_1.pinMode(P1, OUTPUT);
  pcf8574_1.pinMode(P2, OUTPUT);
  pcf8574_1.pinMode(P3, OUTPUT);
  pcf8574_1.pinMode(P4, OUTPUT);
  pcf8574_1.pinMode(P5, OUTPUT);
  pcf8574_1.pinMode(P6, OUTPUT);
  pcf8574_1.pinMode(P7, OUTPUT);

  pcf8574_2.pinMode(P0, OUTPUT);
  pcf8574_2.pinMode(P1, OUTPUT);
  pcf8574_2.pinMode(P2, OUTPUT);
  pcf8574_2.pinMode(P3, OUTPUT);
  pcf8574_2.pinMode(P4, OUTPUT);
  pcf8574_2.pinMode(P5, OUTPUT);
  pcf8574_2.pinMode(P6, OUTPUT);
  pcf8574_2.pinMode(P7, OUTPUT);

  pcf8574_1.begin();
  pcf8574_2.begin();
}

void loop()
{
if(digitalRead(buttonPin)==0)
{
      pcf8574_1.digitalWrite(P0, LOW);  delay(100);
    pcf8574_1.digitalWrite(P1, LOW);  delay(100);
    pcf8574_1.digitalWrite(P2, LOW);  delay(100);
    pcf8574_1.digitalWrite(P3, LOW);  delay(100);
    pcf8574_1.digitalWrite(P4, LOW);  delay(100);
    pcf8574_1.digitalWrite(P5, LOW);  delay(100);
    pcf8574_1.digitalWrite(P6, LOW);  delay(100);
    pcf8574_1.digitalWrite(P7, LOW);  delay(100);
 
    pcf8574_2.digitalWrite(P0, LOW);  delay(100);
    pcf8574_2.digitalWrite(P1, LOW);  delay(100);
    pcf8574_2.digitalWrite(P2, LOW);  delay(100);
    pcf8574_2.digitalWrite(P3, LOW);  delay(100); 
    pcf8574_2.digitalWrite(P4, LOW);  delay(100);
    pcf8574_2.digitalWrite(P5, LOW);  delay(100);
    pcf8574_2.digitalWrite(P6, LOW);  delay(100);
    pcf8574_2.digitalWrite(P7, LOW);  delay(100);
  }
  else
  {
    pcf8574_1.digitalWrite(P0, HIGH);  delay(100);
    pcf8574_1.digitalWrite(P1, HIGH);  delay(100);
    pcf8574_1.digitalWrite(P2, HIGH);  delay(100);
    pcf8574_1.digitalWrite(P3, HIGH);  delay(100);
    pcf8574_1.digitalWrite(P4, HIGH);  delay(100);
    pcf8574_1.digitalWrite(P5, HIGH);  delay(100);
    pcf8574_1.digitalWrite(P6, HIGH);  delay(100);
    pcf8574_1.digitalWrite(P7, HIGH);  delay(100);
 
    pcf8574_2.digitalWrite(P0, HIGH);  delay(100);
    pcf8574_2.digitalWrite(P1, HIGH);  delay(100);
    pcf8574_2.digitalWrite(P2, HIGH);  delay(100);
    pcf8574_2.digitalWrite(P3, HIGH);  delay(100); 
    pcf8574_2.digitalWrite(P4, HIGH);  delay(100);
    pcf8574_2.digitalWrite(P5, HIGH);  delay(100);
    pcf8574_2.digitalWrite(P6, HIGH);  delay(100);
    pcf8574_2.digitalWrite(P7, HIGH);  delay(100);
  }
}