# if() function does not appear to be working. Help?

Hey everyone,
I am trying to display the values of an array with sixteen values so that they are organized as such when they are sent to the serial monitor:

Array[12] Array[13] Array[14] Array[15]
Array[8] Array[9] Array[10] Array[11]
Array[4] Array[5] Array[6] Array[7]
Array[0] Array[1] Array[2] Array[3]
Empty space for one line
then it repeats with the next values of the array

The problem is I cant make the program create an empty space next when it finishes on array value 3 (Array[3])
My code web browser doesn’t let me paste my code into this box so I have attached the code to my post. The part that isnt working is the senddata() function.

Instead of what I am trying to accomplish above, it just does four rows of values continuously with no line space after each sixteen values are displayed. Please take a look at my code and maybe you can help me.

The senddata() function is the at the bottom of the program.

ThermopileSensor.ino (1.63 KB)

if(a == 0 & b == 3){

Wrong usage of &.

& is a bitwise AND. B00011101 & B11010100 equals B00010100.

For a logical AND conjunction, you use &&:

``````if(a==0 && b==3) {
``````

Ahhhhh. That makes sense now. Thank you very much.

I changed that, but it still does not create a space in between every four rows. Any idea what is going on?

``````void senddata(){
for(int a = 3; a>=0; a--){ //for loop for organizing the display of array
for(int b = 0; b<=3; b++){ //second for loop used for organizing the display of the array
if(a == 0 & b == 3){ //This is the part that isnt working!! tests to see whether the array is on its value or Array[3]/Thermo[3]
Serial.println(Thermo[(b+(a*4))]); //The equation i used to organize the values in the way i wanted
Serial.println("\n\n"); //This should create an empty line beneath the values?
}
else if(b==3){ //this returns so that there is four values in each line
Serial.println(Thermo[(b+(a*4))]); //organizes values this is the first value of each of the four lines
}
else{
Serial.print(Thermo[(b+(a*4))]); // all the other values
Serial.print("\t");
}
}
}
}
``````

Try this, using \t - tab helps to line up data, \n - new line.

``````      if(a == 0 & b == 3){ //This is the part that isnt working!! tests to see whether the array is on its value or Array[3]/Thermo[3]
``````

Still has &, instead of &&.

If you changed your code, you need to post it again.

I changed it to what magician suggested and it works great now. Thanks everyone for the help.