05-06-2023, 01:16 AM
[Arduino source code for KC868-A32M]-07_PCF8574_DO
Code:
/*kc868-a32m pcf8575 out*/
#include "Arduino.h"
#include "PCF8574.h"
#define a 100
// Set i2c address
PCF8574 pcf8574_R1(0x23,4,5);
PCF8574 pcf8574_R2(0x24,4,5);
PCF8574 pcf8574_R3(0x25,4,5);
PCF8574 pcf8574_R4(0x26,4,5);
void setup()
{
Serial.begin(115200);
Wire.begin();
for(int i=0;i<=7;i++){
pcf8574_R1.pinMode(i,OUTPUT);
pcf8574_R2.pinMode(i,OUTPUT);
pcf8574_R3.pinMode(i,OUTPUT);
pcf8574_R4.pinMode(i,OUTPUT);
}
pcf8574_R1.begin();
pcf8574_R2.begin();
pcf8574_R3.begin();
pcf8574_R4.begin();
for(int j=0;j<=31;j++){
if(j<=7){
pcf8574_R1.digitalWrite(j,LOW);
delay(a);
}
if(7<j<=15){
pcf8574_R2.digitalWrite(j-8,LOW);
delay(a);
}
if(15<j<=23){
pcf8574_R3.digitalWrite(j-16,LOW);
delay(a);
}
if(23<j<=31){
pcf8574_R4.digitalWrite(j-24,LOW);
delay(a);
}
}
for(int j=0;j<=31;j++){
if(j<=7){
pcf8574_R1.digitalWrite(j,HIGH);
delay(a);
}
if(7<j<=15){
pcf8574_R2.digitalWrite(j-8,HIGH);
delay(a);
}
if(15<j<=23){
pcf8574_R3.digitalWrite(j-16,HIGH);
delay(a);
}
if(23<j<=31){
pcf8574_R4.digitalWrite(j-24,HIGH);
delay(a);
}
}
}
void loop()
{
}