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



[Arduino source code for KC868-A4S]-03 DI - KinCony Support - 03-02-2023

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

// Set i2c address
PCF8574 pcf8574_IN1(0x22,4,16);
unsigned long timeElapsed;
void setup()
{
    Serial.begin(115200);
    delay(1000);

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

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) {Serial.println("Key1 Pressed");}
if (val2==LOW) {Serial.println("Key2 Pressed");}
if (val3==LOW) {Serial.println("Key3 Pressed");}
if (val4==LOW) {Serial.println("Key4 Pressed");}
if (val5==LOW) {Serial.println("Key5 Pressed");}
if (val6==LOW) {Serial.println("Key6 Pressed");}
if (val7==LOW) {Serial.println("Key7 Pressed");}
if (val8==LOW) {Serial.println("Key8 Pressed");}

delay(20);
}