Smart Home Automation Forum
[Arduino IDE demo source code for KC868-A8]--#07-PCF8574-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-A8 (https://www.kincony.com/forum/forumdisplay.php?fid=23)
+--- Thread: [Arduino IDE demo source code for KC868-A8]--#07-PCF8574-DO (/showthread.php?tid=1610)



[Arduino IDE demo source code for KC868-A8]--#07-PCF8574-DO - KinCony Support - 01-05-2022

Code 6: //The demo code is PCF8574-DO    You can copy the code to your Arduino IDE

Code:
#include "Arduino.h"
#include "PCF8574.h"

// Set i2c address
PCF8574 pcf8574(0x24,4,5); // 0x24 is address   IO4 is SDA   IO5 is SCL

void setup()
{
    Serial.begin(115200);
//    delay(1000);

    // Set pinMode to OUTPUT
    pcf8574.pinMode(P0, OUTPUT);
  pcf8574.pinMode(P1, OUTPUT);
  pcf8574.pinMode(P2, OUTPUT);
  pcf8574.pinMode(P3, OUTPUT);
  pcf8574.pinMode(P4, OUTPUT);
  pcf8574.pinMode(P5, OUTPUT);
  pcf8574.pinMode(P6, OUTPUT);
  pcf8574.pinMode(P7, OUTPUT);
//    pcf8574.pinMode(P1, INPUT);

    Serial.print("Init pcf8574...");
    if (pcf8574.begin()){
        Serial.println("OK");
    }else{
        Serial.println("KO");
    }
}

void loop()
{
    pcf8574.digitalWrite(P0, HIGH);
  delay(300);
  pcf8574.digitalWrite(P0, LOW);
  delay(300);
}