Code:
/*KC868-M16 read 16 channels*/
#include "Arduino.h"
#define SDA 4
#define SCL 5
#define a 50
#define s0 32
#define s1 33
#define s2 13
#define s3 16
#define IN3 35
void setup()
{
Serial.begin(115200);
pinMode(s0,OUTPUT);
pinMode(s1,OUTPUT);
pinMode(s2,OUTPUT);
pinMode(s3,OUTPUT);
pinMode(IN3,INPUT);
}
void loop()
{
for(int j=1;j<17;j++){
if(j==1){
truth_table01();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH1=%d\n",analogRead(IN3));
}
}
if(j==2){
truth_table02();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH2=%d\n",analogRead(IN3));
}
}
if(j==3){
truth_table03();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH3=%d\n",analogRead(IN3));
}
}
if(j==4){
truth_table04();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH4=%d\n",analogRead(IN3));
}
}
if(j==5){
truth_table05();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH5=%d\n",analogRead(IN3));
}
}
if(j==6){
truth_table06();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH6=%d\n",analogRead(IN3));
}
}
if(j==7){
truth_table07();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH7=%d\n",analogRead(IN3));
}
}
if(j==8){
truth_table08();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH8=%d\n",analogRead(IN3));
}
}
if(j==9){
truth_table09();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH9=%d\n",analogRead(IN3));
}
}
if(j==10){
truth_table10();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH10=%d\n",analogRead(IN3));
}
}
if(j==11){
truth_table11();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH11=%d\n",analogRead(IN3));
}
}
if(j==12){
truth_table12();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH12=%d\n",analogRead(IN3));
}
}
if(j==13){
truth_table13();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH13=%d\n",analogRead(IN3));
}
}
if(j==14){
truth_table14();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH14=%d\n",analogRead(IN3));
}
}
if(j==15){
truth_table15();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH15=%d\n",analogRead(IN3));
}
}
if(j==16){
truth_table16();
if(analogRead(IN3)!=0){
Serial.printf("A3 on CH16=%d\n",analogRead(IN3));
}
}
delay(20);
}
//}
}
void truth_table01()
{
digitalWrite(s0,LOW);
digitalWrite(s1,LOW);
digitalWrite(s2,LOW);
digitalWrite(s3,LOW);
}
void truth_table02()
{
digitalWrite(s0,HIGH);
digitalWrite(s1,LOW);
digitalWrite(s2,LOW);
digitalWrite(s3,LOW);
}
void truth_table03()
{
digitalWrite(s0,LOW);
digitalWrite(s1,HIGH);
digitalWrite(s2,LOW);
digitalWrite(s3,LOW);
}
void truth_table04()
{
digitalWrite(s0,HIGH);
digitalWrite(s1,HIGH);
digitalWrite(s2,LOW);
digitalWrite(s3,LOW);
}
void truth_table05()
{
digitalWrite(s0,LOW);
digitalWrite(s1,LOW);
digitalWrite(s2,HIGH);
digitalWrite(s3,LOW);
}
void truth_table06()
{
digitalWrite(s0,HIGH);
digitalWrite(s1,LOW);
digitalWrite(s2,HIGH);
digitalWrite(s3,LOW);
}
void truth_table07()
{
digitalWrite(s0,LOW);
digitalWrite(s1,HIGH);
digitalWrite(s2,HIGH);
digitalWrite(s3,LOW);
}
void truth_table08()
{
digitalWrite(s0,HIGH);
digitalWrite(s1,HIGH);
digitalWrite(s2,HIGH);
digitalWrite(s3,LOW);
}
void truth_table09()
{
digitalWrite(s0,LOW);
digitalWrite(s1,LOW);
digitalWrite(s2,LOW);
digitalWrite(s3,HIGH);
}
void truth_table10()
{
digitalWrite(s0,HIGH);
digitalWrite(s1,LOW);
digitalWrite(s2,LOW);
digitalWrite(s3,HIGH);
}
void truth_table11()
{
digitalWrite(s0,LOW);
digitalWrite(s1,HIGH);
digitalWrite(s2,LOW);
digitalWrite(s3,HIGH);
}
void truth_table12()
{
digitalWrite(s0,HIGH);
digitalWrite(s1,HIGH);
digitalWrite(s2,LOW);
digitalWrite(s3,HIGH);
}
void truth_table13()
{
digitalWrite(s0,LOW);
digitalWrite(s1,LOW);
digitalWrite(s2,HIGH);
digitalWrite(s3,HIGH);
}
void truth_table14()
{
digitalWrite(s0,HIGH);
digitalWrite(s1,LOW);
digitalWrite(s2,HIGH);
digitalWrite(s3,HIGH);
}
void truth_table15()
{
digitalWrite(s0,LOW);
digitalWrite(s1,HIGH);
digitalWrite(s2,HIGH);
digitalWrite(s3,HIGH);
}
void truth_table16()
{
digitalWrite(s0,HIGH);
digitalWrite(s1,HIGH);
digitalWrite(s2,HIGH);
digitalWrite(s3,HIGH);
}