03-23-2023, 01:24 AM
(This post was last modified: 03-23-2023, 01:30 AM by KinCony Support.)
[Arduino source code for KC868-AIO]-08 DIGITAL_INPUT
Code:
#include "Arduino.h"
#include "PCF8575.h"
// Set i2c address
PCF8575 pcf8575_IN1(0x21,4,16);
PCF8575 pcf8575_IN2(0x22,4,16);
PCF8575 pcf8575_IN3(0x23,4,16);
PCF8575 pcf8575_IN4(0x26,4,16);
unsigned long timeElapsed;
void setup()
{
Serial.begin(115200);
pcf8575_IN1.begin();
pcf8575_IN2.begin();
pcf8575_IN3.begin();
pcf8575_IN4.begin();
pcf8575_IN1.pinMode(P0,INPUT);
pcf8575_IN1.pinMode(P1,INPUT);
pcf8575_IN1.pinMode(P2,INPUT);
pcf8575_IN1.pinMode(P3,INPUT);
pcf8575_IN1.pinMode(P4,INPUT);
pcf8575_IN1.pinMode(P5,INPUT);
pcf8575_IN1.pinMode(P6,INPUT);
pcf8575_IN1.pinMode(P7,INPUT);
pcf8575_IN1.pinMode(P8,INPUT);
pcf8575_IN1.pinMode(P9,INPUT);
pcf8575_IN1.pinMode(P10,INPUT);
pcf8575_IN1.pinMode(P11,INPUT);
pcf8575_IN1.pinMode(P12,INPUT);
pcf8575_IN1.pinMode(P13,INPUT);
pcf8575_IN1.pinMode(P14,INPUT);
pcf8575_IN1.pinMode(P15,INPUT);
pcf8575_IN2.pinMode(P0,INPUT);
pcf8575_IN2.pinMode(P1,INPUT);
pcf8575_IN2.pinMode(P2,INPUT);
pcf8575_IN2.pinMode(P3,INPUT);
pcf8575_IN2.pinMode(P4,INPUT);
pcf8575_IN2.pinMode(P5,INPUT);
pcf8575_IN2.pinMode(P6,INPUT);
pcf8575_IN2.pinMode(P7,INPUT);
pcf8575_IN2.pinMode(P8,INPUT);
pcf8575_IN2.pinMode(P9,INPUT);
pcf8575_IN2.pinMode(P10,INPUT);
pcf8575_IN2.pinMode(P11,INPUT);
pcf8575_IN2.pinMode(P12,INPUT);
pcf8575_IN2.pinMode(P13,INPUT);
pcf8575_IN2.pinMode(P14,INPUT);
pcf8575_IN2.pinMode(P15,INPUT);
pcf8575_IN3.pinMode(P0,INPUT);
pcf8575_IN3.pinMode(P1,INPUT);
pcf8575_IN3.pinMode(P2,INPUT);
pcf8575_IN3.pinMode(P3,INPUT);
pcf8575_IN3.pinMode(P4,INPUT);
pcf8575_IN3.pinMode(P5,INPUT);
pcf8575_IN3.pinMode(P6,INPUT);
pcf8575_IN3.pinMode(P7,INPUT);
pcf8575_IN3.pinMode(P8,INPUT);
pcf8575_IN3.pinMode(P9,INPUT);
pcf8575_IN3.pinMode(P10,INPUT);
pcf8575_IN3.pinMode(P11,INPUT);
pcf8575_IN3.pinMode(P12,INPUT);
pcf8575_IN3.pinMode(P13,INPUT);
pcf8575_IN3.pinMode(P14,INPUT);
pcf8575_IN3.pinMode(P15,INPUT);
pcf8575_IN4.pinMode(P0,INPUT);
pcf8575_IN4.pinMode(P1,INPUT);
pcf8575_IN4.pinMode(P2,INPUT);
pcf8575_IN4.pinMode(P3,INPUT);
pcf8575_IN4.pinMode(P4,INPUT);
pcf8575_IN4.pinMode(P5,INPUT);
pcf8575_IN4.pinMode(P6,INPUT);
pcf8575_IN4.pinMode(P7,INPUT);
pcf8575_IN4.pinMode(P8,OUTPUT);
pcf8575_IN4.pinMode(P9,OUTPUT);
pcf8575_IN4.pinMode(P10,OUTPUT);
pcf8575_IN4.pinMode(P11,OUTPUT);
pcf8575_IN4.pinMode(P12,OUTPUT);
pcf8575_IN4.pinMode(P13,OUTPUT);
pcf8575_IN4.pinMode(P14,INPUT);
pcf8575_IN4.pinMode(P15,INPUT);
}
void loop()
{
uint16_t var_rcv = 0;
var_rcv = pcf8575_IN1.digitalReadAll();
if (var_rcv!=65535)
{
Serial.print("input16-input1 state:");
Serial.println(var_rcv,BIN);
}
var_rcv = pcf8575_IN2.digitalReadAll();
if (var_rcv!=65535)
{
Serial.print("input32-input17 state:");
Serial.println(var_rcv,BIN);
}
var_rcv = pcf8575_IN3.digitalReadAll();
if (var_rcv!=65535)
{
Serial.print("input48-input33 state:");
Serial.println(var_rcv,BIN);
}
var_rcv = pcf8575_IN4.digitalReadAll();
if (var_rcv!=65535)
{
Serial.print("input64-input49 state:");
Serial.println(var_rcv,BIN);
}
delay(500);
}