05-12-2022, 07:35 AM
(This post was last modified: 05-12-2022, 07:49 AM by KinCony Support.)
[Arduino IDE demo source code for KC868-A64]--#04-PCF8575_Output_code
Code:
/*www.kincony.com */
/*KC868-A64 Code of PCF8575 output*/
#include "Arduino.h"
#include "PCF8575.h"
// Set i2c address
PCF8575 pcf8575_R1(0x24,5,16); //SDA IO5 , SCL IO16
PCF8575 pcf8575_R2(0x25,5,16);
PCF8575 pcf8575_R3(0x21,5,16);
PCF8575 pcf8575_R4(0x22,5,16);
unsigned long timeElapsed;
void setup()
{
Serial.begin(115200);
for(int i=0;i<16;i++)
{
pcf8575_R1.pinMode(i,OUTPUT);
pcf8575_R2.pinMode(i,OUTPUT);
pcf8575_R3.pinMode(i,OUTPUT);
pcf8575_R4.pinMode(i,OUTPUT);
}
pcf8575_R1.begin();
pcf8575_R2.begin();
pcf8575_R3.begin();
pcf8575_R4.begin();
/*
pcf8575_R1.pinMode(P0,OUTPUT);
pcf8575_R1.pinMode(P1,OUTPUT);
pcf8575_R1.pinMode(P2,OUTPUT);
pcf8575_R1.pinMode(P3,OUTPUT);
pcf8575_R1.pinMode(P4,OUTPUT);
pcf8575_R1.pinMode(P5,OUTPUT);
pcf8575_R1.pinMode(P6,OUTPUT);
pcf8575_R1.pinMode(P7,OUTPUT);
pcf8575_R1.pinMode(P8,OUTPUT);
pcf8575_R1.pinMode(P9,OUTPUT);
pcf8575_R1.pinMode(P10,OUTPUT);
pcf8575_R1.pinMode(P11,OUTPUT);
pcf8575_R1.pinMode(P12,OUTPUT);
pcf8575_R1.pinMode(P13,OUTPUT);
pcf8575_R1.pinMode(P14,OUTPUT);
pcf8575_R1.pinMode(P15,OUTPUT);
pcf8575_R2.pinMode(P0,OUTPUT);
pcf8575_R2.pinMode(P1,OUTPUT);
pcf8575_R2.pinMode(P2,OUTPUT);
pcf8575_R2.pinMode(P3,OUTPUT);
pcf8575_R2.pinMode(P4,OUTPUT);
pcf8575_R2.pinMode(P5,OUTPUT);
pcf8575_R2.pinMode(P6,OUTPUT);
pcf8575_R2.pinMode(P7,OUTPUT);
pcf8575_R2.pinMode(P8,OUTPUT);
pcf8575_R2.pinMode(P9,OUTPUT);
pcf8575_R2.pinMode(P10,OUTPUT);
pcf8575_R2.pinMode(P11,OUTPUT);
pcf8575_R2.pinMode(P12,OUTPUT);
pcf8575_R2.pinMode(P13,OUTPUT);
pcf8575_R2.pinMode(P14,OUTPUT);
pcf8575_R2.pinMode(P15,OUTPUT);
pcf8575_R3.pinMode(P0,OUTPUT);
pcf8575_R3.pinMode(P1,OUTPUT);
pcf8575_R3.pinMode(P2,OUTPUT);
pcf8575_R3.pinMode(P3,OUTPUT);
pcf8575_R3.pinMode(P4,OUTPUT);
pcf8575_R3.pinMode(P5,OUTPUT);
pcf8575_R3.pinMode(P6,OUTPUT);
pcf8575_R3.pinMode(P7,OUTPUT);
pcf8575_R3.pinMode(P8,OUTPUT);
pcf8575_R3.pinMode(P9,OUTPUT);
pcf8575_R3.pinMode(P10,OUTPUT);
pcf8575_R3.pinMode(P11,OUTPUT);
pcf8575_R3.pinMode(P12,OUTPUT);
pcf8575_R3.pinMode(P13,OUTPUT);
pcf8575_R3.pinMode(P14,OUTPUT);
pcf8575_R3.pinMode(P15,OUTPUT);
pcf8575_R4.pinMode(P0,OUTPUT);
pcf8575_R4.pinMode(P1,OUTPUT);
pcf8575_R4.pinMode(P2,OUTPUT);
pcf8575_R4.pinMode(P3,OUTPUT);
pcf8575_R4.pinMode(P4,OUTPUT);
pcf8575_R4.pinMode(P5,OUTPUT);
pcf8575_R4.pinMode(P6,OUTPUT);
pcf8575_R4.pinMode(P7,OUTPUT);
pcf8575_R4.pinMode(P8,OUTPUT);
pcf8575_R4.pinMode(P9,OUTPUT);
pcf8575_R4.pinMode(P10,OUTPUT);
pcf8575_R4.pinMode(P11,OUTPUT);
pcf8575_R4.pinMode(P12,OUTPUT);
pcf8575_R4.pinMode(P13,OUTPUT);
pcf8575_R4.pinMode(P14,OUTPUT);
pcf8575_R4.pinMode(P15,OUTPUT); */
}
void loop()
{
for(int j=0;j<16;j++)
{
pcf8575_R1.digitalWrite(j,LOW); delay(50);
}
for(int j=0;j<16;j++)
{
pcf8575_R2.digitalWrite(j,LOW); delay(50);
}
for(int j=0;j<16;j++)
{
pcf8575_R3.digitalWrite(j,LOW); delay(50);
}
for(int j=0;j<16;j++)
{
pcf8575_R4.digitalWrite(j,LOW); delay(50);
}
for(int j=0;j<16;j++)
{
pcf8575_R1.digitalWrite(j,HIGH); delay(50);
}
for(int j=0;j<16;j++)
{
pcf8575_R2.digitalWrite(j,HIGH); delay(50);
}
for(int j=0;j<16;j++)
{
pcf8575_R3.digitalWrite(j,HIGH); delay(50);
}
for(int j=0;j<16;j++)
{
pcf8575_R4.digitalWrite(j,HIGH); delay(50);
}
/*
//R1 LOW----------------------
pcf8575_R1.digitalWrite(P0,LOW);
delay(50);
pcf8575_R1.digitalWrite(P1,LOW);
delay(50);
pcf8575_R1.digitalWrite(P2,LOW);
delay(50);
pcf8575_R1.digitalWrite(P3,LOW);
delay(50);
pcf8575_R1.digitalWrite(P4,LOW);
delay(50);
pcf8575_R1.digitalWrite(P5,LOW);
delay(50);
pcf8575_R1.digitalWrite(P6,LOW);
delay(50);
pcf8575_R1.digitalWrite(P7,LOW);
delay(50);
pcf8575_R1.digitalWrite(P8,LOW);
delay(50);
pcf8575_R1.digitalWrite(P9,LOW);
delay(50);
pcf8575_R1.digitalWrite(P10,LOW);
delay(50);
pcf8575_R1.digitalWrite(P11,LOW);
delay(50);
pcf8575_R1.digitalWrite(P12,LOW);
delay(50);
pcf8575_R1.digitalWrite(P13,LOW);
delay(50);
pcf8575_R1.digitalWrite(P14,LOW);
delay(50);
pcf8575_R1.digitalWrite(P15,LOW);
delay(50);
//R2 LOW------------------------
pcf8575_R2.digitalWrite(P0,LOW);
delay(50);
pcf8575_R2.digitalWrite(P1,LOW);
delay(50);
pcf8575_R2.digitalWrite(P2,LOW);
delay(50);
pcf8575_R2.digitalWrite(P3,LOW);
delay(50);
pcf8575_R2.digitalWrite(P4,LOW);
delay(50);
pcf8575_R2.digitalWrite(P5,LOW);
delay(50);
pcf8575_R2.digitalWrite(P6,LOW);
delay(50);
pcf8575_R2.digitalWrite(P7,LOW);
delay(50);
pcf8575_R2.digitalWrite(P8,LOW);
delay(50);
pcf8575_R2.digitalWrite(P9,LOW);
delay(50);
pcf8575_R2.digitalWrite(P10,LOW);
delay(50);
pcf8575_R2.digitalWrite(P11,LOW);
delay(50);
pcf8575_R2.digitalWrite(P12,LOW);
delay(50);
pcf8575_R2.digitalWrite(P13,LOW);
delay(50);
pcf8575_R2.digitalWrite(P14,LOW);
delay(50);
pcf8575_R2.digitalWrite(P15,LOW);
delay(50);
//R3 LOW------------------------
pcf8575_R3.digitalWrite(P0,LOW);
delay(50);
pcf8575_R3.digitalWrite(P1,LOW);
delay(50);
pcf8575_R3.digitalWrite(P2,LOW);
delay(50);
pcf8575_R3.digitalWrite(P3,LOW);
delay(50);
pcf8575_R3.digitalWrite(P4,LOW);
delay(50);
pcf8575_R3.digitalWrite(P5,LOW);
delay(50);
pcf8575_R3.digitalWrite(P6,LOW);
delay(50);
pcf8575_R3.digitalWrite(P7,LOW);
delay(50);
pcf8575_R3.digitalWrite(P8,LOW);
delay(50);
pcf8575_R3.digitalWrite(P9,LOW);
delay(50);
pcf8575_R3.digitalWrite(P10,LOW);
delay(50);
pcf8575_R3.digitalWrite(P11,LOW);
delay(50);
pcf8575_R3.digitalWrite(P12,LOW);
delay(50);
pcf8575_R3.digitalWrite(P13,LOW);
delay(50);
pcf8575_R3.digitalWrite(P14,LOW);
delay(50);
pcf8575_R3.digitalWrite(P15,LOW);
delay(50);
//R4 LOW------------------------
pcf8575_R4.digitalWrite(P0,LOW);
delay(50);
pcf8575_R4.digitalWrite(P1,LOW);
delay(50);
pcf8575_R4.digitalWrite(P2,LOW);
delay(50);
pcf8575_R4.digitalWrite(P3,LOW);
delay(50);
pcf8575_R4.digitalWrite(P4,LOW);
delay(50);
pcf8575_R4.digitalWrite(P5,LOW);
delay(50);
pcf8575_R4.digitalWrite(P6,LOW);
delay(50);
pcf8575_R4.digitalWrite(P7,LOW);
delay(50);
pcf8575_R4.digitalWrite(P8,LOW);
delay(50);
pcf8575_R4.digitalWrite(P9,LOW);
delay(50);
pcf8575_R4.digitalWrite(P10,LOW);
delay(50);
pcf8575_R4.digitalWrite(P11,LOW);
delay(50);
pcf8575_R4.digitalWrite(P12,LOW);
delay(50);
pcf8575_R4.digitalWrite(P13,LOW);
delay(50);
pcf8575_R4.digitalWrite(P14,LOW);
delay(50);
pcf8575_R4.digitalWrite(P15,LOW);
delay(50);
//R1 HIGH-----------------------
pcf8575_R1.digitalWrite(P0,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P1,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P2,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P3,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P4,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P5,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P6,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P7,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P8,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P9,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P10,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P11,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P12,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P13,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P14,HIGH);
delay(50);
pcf8575_R1.digitalWrite(P15,HIGH);
delay(50);
//R3 HIGH------------------------
pcf8575_R2.digitalWrite(P0,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P1,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P2,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P3,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P4,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P5,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P6,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P7,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P8,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P9,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P10,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P11,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P12,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P13,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P14,HIGH);
delay(50);
pcf8575_R2.digitalWrite(P15,HIGH);
delay(50);
//R3 HIGH-----------------------
pcf8575_R3.digitalWrite(P0,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P1,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P2,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P3,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P4,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P5,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P6,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P7,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P8,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P9,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P10,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P11,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P12,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P13,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P14,HIGH);
delay(50);
pcf8575_R3.digitalWrite(P15,HIGH);
delay(50);
//R4 HIGH------------------------
pcf8575_R4.digitalWrite(P0,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P1,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P2,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P3,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P4,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P5,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P6,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P7,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P8,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P9,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P10,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P11,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P12,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P13,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P14,HIGH);
delay(50);
pcf8575_R4.digitalWrite(P15,HIGH);
delay(50);
*/
}