01-05-2022, 06:35 AM
(This post was last modified: 01-05-2022, 07:36 AM by KinCony Support.)
Code 2: //The demo code is ADC INPUT You can copy the code to your Arduino IDE
Code:
#include "Arduino.h"
#include "PCF8574.h" //install library "PCF8574 library"
#define ANALOG_A1 34 // IO34 Board: V1.4
#define ANALOG_A2 35 // IO35 Board: V1.4
byte out_arr[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
// Set i2c address
//TwoWire my_def
PCF8574 pcf8574_input(0x22);
PCF8574 pcf8574_output(0x24);
byte value = 0;
void setup()
{
Serial.begin(115200);
delay(1000);
pinMode(ANALOG_A1,INPUT);
pinMode(ANALOG_A2,INPUT);
// Set pinMode to OUTPUT
pcf8574_output.pinMode(P0, OUTPUT);
pcf8574_output.pinMode(P1, OUTPUT);
pcf8574_output.pinMode(P2, OUTPUT);
pcf8574_output.pinMode(P3, OUTPUT);
pcf8574_output.pinMode(P4, OUTPUT);
pcf8574_output.pinMode(P5, OUTPUT);
pcf8574_output.pinMode(P6, OUTPUT);
pcf8574_output.pinMode(P7, OUTPUT);
Serial.print("Init pcf8574 output...");
if (pcf8574_output.begin()){
Serial.println("OK");
}else{
Serial.println("failed");
}
pcf8574_input.pinMode(P0, INPUT);
pcf8574_input.pinMode(P1, INPUT);
pcf8574_input.pinMode(P2, INPUT);
pcf8574_input.pinMode(P3, INPUT);
pcf8574_input.pinMode(P4, INPUT);
pcf8574_input.pinMode(P5, INPUT);
pcf8574_input.pinMode(P6, INPUT);
pcf8574_input.pinMode(P7, INPUT);
Serial.print("Init pcf8574 input...");
if (pcf8574_input.begin()){
Serial.println("OK");
}else{
Serial.println("failed");
}
}
void loop()
{
delay(500);
Serial.printf("Current Reading A1 on Pin(%d)=%d\n",ANALOG_A1,analogRead(ANALOG_A1));
Serial.printf("Current Reading A2 on Pin(%d)=%d\n",ANALOG_A2,analogRead(ANALOG_A2));
}