Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please explain this code to me or at least put comments on the code

ID: 2292409 • Letter: C

Question

Can someone please explain this code to me or at least put comments on the code

int x,y,z,t,r,s;

int a=3;
int b=4;
int c=5;
int d=6;

void setup() {
pinMode(a,INPUT);  
pinMode(b,INPUT);
pinMode(c,INPUT);
pinMode(d,INPUT);
Serial.begin(9600);
}

void loop() {
char e[16];
String command;

x=digitalRead(a);

y=digitalRead(b);

z=digitalRead(c);

t=digitalRead(d);


if (x==0 && y==0 && z==0 && t==0)
e[0]='1';
if (x==0 && y==0 && z==0 && t==1)
e[1]='2';
if (x==0 && y==0 && z==1 && t==0)
e[2]='3';
if (x==0 && y==0 && z==1 && t==1)
e[3]='4';
if (x==0 && y==1 && z==0 && t==0)
e[4]='5';
if (x==0 && y==1 && z==0 && t==1)
e[5]='6';
if (x==0 && y==1 && z==1 && t==0)
e[6]='7';
if (x==0 && y==1 && z==1 && t==1)
e[7]='8';
if (x==1 && y==0 && z==0 && t==0)
e[8]='9';
if (x==1 && y==0 && z==0 && t==1)
e[9]="11";
if (x==1 && y==0 && z==1 && t==0)
e[10]="12";
if (x==1 && y==0 && z==1 && t==1)
e[11]="13";
if (x==1 && y==1 && z==0 && t==0)
e[12]="14";
if (x==1 && y==1 && z==0 && t==1)
e[13]="15";
if (x==1 && y==1 && z==1 && t==0)
e[14]="16";
if (x==1 && y==1 && z==1 && t==1)
e[15]='2';


for(r=0;r<16;r++)
{
for(s=0;s<16;s++)
{
command=e[r]+e[s];
}
}


if(command="1")
{
Serial.print("First devices");

// it can be continued to 256 devices
}
}


}

Explanation / Answer

int x,y,z,t,r,s; //defining variables

int a=3;
int b=4;
int c=5;
int d=6;

void setup() {
pinMode(a,INPUT);  
pinMode(b,INPUT); //Configures the specified pin to behave either as an input or an outpu
pinMode(c,INPUT);
pinMode(d,INPUT);
Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial data transmission
}

void loop() {
char e[16];
String command;

x=digitalRead(a);

y=digitalRead(b);

z=digitalRead(c); //Reads the value from a specified digital pin, either HIGH or LOW

t=digitalRead(d);


if (x==0 && y==0 && z==0 && t==0)
e[0]='1';
if (x==0 && y==0 && z==0 && t==1) //if conditional loops
e[1]='2';
if (x==0 && y==0 && z==1 && t==0)
e[2]='3';
if (x==0 && y==0 && z==1 && t==1)
e[3]='4';
if (x==0 && y==1 && z==0 && t==0)
e[4]='5';
if (x==0 && y==1 && z==0 && t==1)
e[5]='6';
if (x==0 && y==1 && z==1 && t==0)
e[6]='7';
if (x==0 && y==1 && z==1 && t==1)
e[7]='8';
if (x==1 && y==0 && z==0 && t==0)
e[8]='9';
if (x==1 && y==0 && z==0 && t==1)
e[9]="11";
if (x==1 && y==0 && z==1 && t==0)
e[10]="12";
if (x==1 && y==0 && z==1 && t==1)
e[11]="13";
if (x==1 && y==1 && z==0 && t==0)
e[12]="14";
if (x==1 && y==1 && z==0 && t==1)
e[13]="15";
if (x==1 && y==1 && z==1 && t==0)
e[14]="16";
if (x==1 && y==1 && z==1 && t==1)
e[15]='2';


for(r=0;r<16;r++)
{
for(s=0;s<16;s++)
{
command=e[r]+e[s]; // for conditional loop
}
}


if(command="1")
{
Serial.print("First devices"); //print the value between " "

// it can be continued to 256 devices
}
}


}