03-23-2023, 01:23 AM
(This post was last modified: 03-23-2023, 01:29 AM by KinCony Support.)
[Arduino source code for KC868-AIO]-05 DIGITAL_OUTPUT
Code:
/*KC868-AIO OUTPUT 32 RELAYS*/
#include "Arduino.h"
#include "PCF8575.h"
#define SDA 4
#define SCL 16
#define delaytime 50
// Set i2c address
PCF8575 pcf8575_R1(0x24,SDA,SCL);
PCF8575 pcf8575_R2(0x25,SDA,SCL);
PCF8575 pcf8575_R3(0x26,SDA,SCL);
void setup()
{
Serial.begin(115200);
for(int j=1;j<=3;j++){
if(j==1){
for(int i=0;i<=15;i++){
pcf8575_R1.pinMode(i,OUTPUT);
}
}
if(j==2){
for(int i=0;i<=15;i++){
pcf8575_R2.pinMode(i,OUTPUT);
}
}
if(j==3){
for(int i=0;i<=7;i++){
pcf8575_R3.pinMode(i,INPUT);//0-7 input
}
for(int i=8;i<=13;i++){
pcf8575_R3.pinMode(i,OUTPUT);//8-13 OUTPUT
}
for(int i=14;i<=15;i++){
pcf8575_R3.pinMode(i,INPUT);//14-15 INPUT
}
}
}
pcf8575_R1.begin();
pcf8575_R2.begin();
pcf8575_R3.begin();
}
void loop()
{
for(int j=1;j<=3;j++){
if(j==1){
for(int i=0;i<=15;i++){
pcf8575_R1.digitalWrite(i,LOW);
delay(delaytime);
}
}
if(j==2){
for(int i=0;i<=15;i++){
pcf8575_R2.digitalWrite(i,LOW);
delay(delaytime);
}
}
if(j==3){
for(int i=12;i<=13;i++){
pcf8575_R3.digitalWrite(i,LOW);
delay(delaytime);
}
}
}
for(int j=1;j<=3;j++){
if(j==1){
for(int i=0;i<=15;i++){
pcf8575_R1.digitalWrite(i,HIGH);
delay(delaytime);
}
}
if(j==2){
for(int i=0;i<=15;i++){
pcf8575_R2.digitalWrite(i,HIGH);
delay(delaytime);
}
}
if(j==3){
for(int i=12;i<=13;i++){
pcf8575_R3.digitalWrite(i,HIGH);
delay(delaytime);
}
}
}
}