Code:
/*KC868-AIO ADC output*/
#include "Arduino.h"
#include "PCF8575.h"
#define ANALOG_A1 36 // IO36
#define ANALOG_A2 39 // IO39
#define ANALOG_A3 34 // IO34
#define ANALOG_A4 35 // IO35
#define SDA 4
#define SCL 16
#define delaytime 50
// Set i2c address
PCF8575 pcf8575_R3(0x26,SDA,SCL);
void setup()
{
Serial.begin(115200);
pinMode(ANALOG_A1,INPUT);
pinMode(ANALOG_A2,INPUT);
pinMode(ANALOG_A3,INPUT);
pinMode(ANALOG_A4,INPUT);
pcf8575_R3.pinMode(8,OUTPUT);
pcf8575_R3.pinMode(9,OUTPUT);
pcf8575_R3.pinMode(10,OUTPUT);
pcf8575_R3.pinMode(11,OUTPUT);
pcf8575_R3.begin();
}
void loop()
{
for(int j=1;j<17;j++){
if(j==1){
truth_table01();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH1=%d\n",analogRead(ANALOG_A1));
}
}
if(j==2){
truth_table02();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH2=%d\n",analogRead(ANALOG_A1));
}
}
if(j==3){
truth_table03();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH3=%d\n",analogRead(ANALOG_A1));
}
}
if(j==4){
truth_table04();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH4=%d\n",analogRead(ANALOG_A1));
}
}
if(j==5){
truth_table05();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH5=%d\n",analogRead(ANALOG_A1));
}
}
if(j==6){
truth_table06();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH6=%d\n",analogRead(ANALOG_A1));
}
}
if(j==7){
truth_table07();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH7=%d\n",analogRead(ANALOG_A1));
}
}
if(j==8){
truth_table08();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH8=%d\n",analogRead(ANALOG_A1));
}
}
if(j==9){
truth_table09();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH9=%d\n",analogRead(ANALOG_A1));
}
}
if(j==10){
truth_table10();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH10=%d\n",analogRead(ANALOG_A1));
}
}
if(j==11){
truth_table11();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH11=%d\n",analogRead(ANALOG_A1));
}
}
if(j==12){
truth_table12();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH12=%d\n",analogRead(ANALOG_A1));
}
}
if(j==13){
truth_table13();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH13=%d\n",analogRead(ANALOG_A1));
}
}
if(j==14){
truth_table14();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH14=%d\n",analogRead(ANALOG_A1));
}
}
if(j==15){
truth_table15();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH15=%d\n",analogRead(ANALOG_A1));
}
}
if(j==16){
truth_table16();
if(analogRead(ANALOG_A1)!=0){
Serial.printf("A1 on CH16=%d\n",analogRead(ANALOG_A1));
}
}
}
if(analogRead(ANALOG_A2)!=0){Serial.printf("A2 on CH17=%d\n",analogRead(ANALOG_A2));}
if(analogRead(ANALOG_A3)!=0){Serial.printf("A2 on CH18=%d\n",analogRead(ANALOG_A3));}
if(analogRead(ANALOG_A4)!=0){Serial.printf("A2 on CH19=%d\n",analogRead(ANALOG_A4));}
delay(100);
}
void truth_table01()
{
pcf8575_R3.digitalWrite(8,LOW);
pcf8575_R3.digitalWrite(9,LOW);
pcf8575_R3.digitalWrite(10,LOW);
pcf8575_R3.digitalWrite(11,LOW);
}
void truth_table02()
{
pcf8575_R3.digitalWrite(8,HIGH);
pcf8575_R3.digitalWrite(9,LOW);
pcf8575_R3.digitalWrite(10,LOW);
pcf8575_R3.digitalWrite(11,LOW);
}
void truth_table03()
{
pcf8575_R3.digitalWrite(8,LOW);
pcf8575_R3.digitalWrite(9,HIGH);
pcf8575_R3.digitalWrite(10,LOW);
pcf8575_R3.digitalWrite(11,LOW);
}
void truth_table04()
{
pcf8575_R3.digitalWrite(8,HIGH);
pcf8575_R3.digitalWrite(9,HIGH);
pcf8575_R3.digitalWrite(10,LOW);
pcf8575_R3.digitalWrite(11,LOW);
}
void truth_table05()
{
pcf8575_R3.digitalWrite(8,LOW);
pcf8575_R3.digitalWrite(9,LOW);
pcf8575_R3.digitalWrite(10,HIGH);
pcf8575_R3.digitalWrite(11,LOW);
}
void truth_table06()
{
pcf8575_R3.digitalWrite(8,HIGH);
pcf8575_R3.digitalWrite(9,LOW);
pcf8575_R3.digitalWrite(10,HIGH);
pcf8575_R3.digitalWrite(11,LOW);
}
void truth_table07()
{
pcf8575_R3.digitalWrite(8,LOW);
pcf8575_R3.digitalWrite(9,HIGH);
pcf8575_R3.digitalWrite(10,HIGH);
pcf8575_R3.digitalWrite(11,LOW);
}
void truth_table08()
{
pcf8575_R3.digitalWrite(8,HIGH);
pcf8575_R3.digitalWrite(9,HIGH);
pcf8575_R3.digitalWrite(10,HIGH);
pcf8575_R3.digitalWrite(11,LOW);
}
void truth_table09()
{
pcf8575_R3.digitalWrite(8,LOW);
pcf8575_R3.digitalWrite(9,LOW);
pcf8575_R3.digitalWrite(10,LOW);
pcf8575_R3.digitalWrite(11,HIGH);
}
void truth_table10()
{
pcf8575_R3.digitalWrite(8,HIGH);
pcf8575_R3.digitalWrite(9,LOW);
pcf8575_R3.digitalWrite(10,LOW);
pcf8575_R3.digitalWrite(11,HIGH);
}
void truth_table11()
{
pcf8575_R3.digitalWrite(8,LOW);
pcf8575_R3.digitalWrite(9,HIGH);
pcf8575_R3.digitalWrite(10,LOW);
pcf8575_R3.digitalWrite(11,HIGH);
}
void truth_table12()
{
pcf8575_R3.digitalWrite(8,HIGH);
pcf8575_R3.digitalWrite(9,HIGH);
pcf8575_R3.digitalWrite(10,LOW);
pcf8575_R3.digitalWrite(11,HIGH);
}
void truth_table13()
{
pcf8575_R3.digitalWrite(8,LOW);
pcf8575_R3.digitalWrite(9,LOW);
pcf8575_R3.digitalWrite(10,HIGH);
pcf8575_R3.digitalWrite(11,HIGH);
}
void truth_table14()
{
pcf8575_R3.digitalWrite(8,HIGH);
pcf8575_R3.digitalWrite(9,LOW);
pcf8575_R3.digitalWrite(10,HIGH);
pcf8575_R3.digitalWrite(11,HIGH);
}
void truth_table15()
{
pcf8575_R3.digitalWrite(8,LOW);
pcf8575_R3.digitalWrite(9,HIGH);
pcf8575_R3.digitalWrite(10,HIGH);
pcf8575_R3.digitalWrite(11,HIGH);
}
void truth_table16()
{
pcf8575_R3.digitalWrite(8,HIGH);
pcf8575_R3.digitalWrite(9,HIGH);
pcf8575_R3.digitalWrite(10,HIGH);
pcf8575_R3.digitalWrite(11,HIGH);
}