05-13-2022, 05:51 AM
(This post was last modified: 05-13-2022, 05:53 AM by KinCony Support.)
[Arduino IDE demo source code for KC868-A64]--#05-PCF8575_Input_code
you should install the library PCF8575 library
Before Upload the code ,you should find the PCF8575.h in PCF8575 Library file,and enable the the code in below picture
Code:
/*www.kinocny.com */
/*KC868-A64 CODE OF PCF8575 READ INPUT*/
#include "Arduino.h"
#include "PCF8575.h"
// Set i2c address
PCF8575 pcf8575_IN1(0x24,15,4);
PCF8575 pcf8575_IN2(0x25,15,4);
PCF8575 pcf8575_IN3(0x21,15,4);
PCF8575 pcf8575_IN4(0x22,15,4);
void setup()
{
Serial.begin(115200);
pcf8575_IN1.begin();
pcf8575_IN2.begin();
pcf8575_IN3.begin();
pcf8575_IN4.begin();
for(int i=0;i<16;i++)
{
pcf8575_IN1.pinMode(i,INPUT);
pcf8575_IN2.pinMode(i,INPUT);
pcf8575_IN3.pinMode(i,INPUT);
pcf8575_IN4.pinMode(i,INPUT);
}
Serial.println("KC868-A64 64 channel input state 0:ON 1:OFF");
}
void loop()
{
uint16_t var_1 = 0;
uint16_t var_2 = 0;
uint16_t var_3 = 0;
uint16_t var_4 = 0;
var_1 = pcf8575_IN1.digitalReadAll();
var_2 = pcf8575_IN2.digitalReadAll();
var_3 = pcf8575_IN3.digitalReadAll();
var_4 = pcf8575_IN4.digitalReadAll();
/* Detect IN1-IN16 If triggered print "KEY i PRESSED" */
for(int i=0;i<16;i++)
{
if((var_1>>i&1)==0)
{
Serial.print("KEY ");
Serial.print(i+1);
Serial.println(" PRESSED");
}
}
/* Detect IN17-IN32 If triggered print "KEY i PRESSED" */
for(int i=0;i<16;i++)
{
if((var_2>>i&1)==0)
{
Serial.print("KEY ");
Serial.print(i+17);
Serial.println(" PRESSED");
}
}
/* Detect IN33-IN48 If triggered print "KEY i PRESSED" */
for(int i=0;i<16;i++)
{
if((var_3>>i&1)==0)
{
Serial.print("KEY ");
Serial.print(i+33);
Serial.println(" PRESSED");
}
}
/* Detect IN49-IN64 If triggered print "KEY i PRESSED" */
for(int i=0;i<16;i++)
{
if((var_4>>i&1)==0)
{
Serial.print("KEY ");
Serial.print(i+49);
Serial.println(" PRESSED");
}
}
delay(100);
}
you should install the library PCF8575 library
Before Upload the code ,you should find the PCF8575.h in PCF8575 Library file,and enable the the code in below picture