newbe if statment question

sorry for such a simple boring question, but I am pulling my hair out as to why this “If” statement in my function will not resolve the correct answer.

No Matter what address I pass to this function it prints an address correctly, but always actions the first line of my if. No matter what I change the address to that I pass it, it seems to no progress t the else if or the else.
I am sure it is a simple mistake, but I have hashed and rehashed it heaps over the past few days.
The incoming packet is from a loconet network and is a switch command, basically an address, and a status for that address 0 = thrown, 16 = closed

Once I get that sorted I will then work out how to do this without using 16 nested If, if else statements for each IO pin.

Thanks heaps in advance…

Keep in mind there is a heap of missing sketch that sets up the int, and produces the “address”, “output status” and “board addressing”. I didn’t want to clutter the post with excess lines.

// test to see if the swicth address is for this board, if so identify the output state
void Outputtest(int address, int LNstat, int Boardmin)
// this needs to be done better either using switch/case method or array’s.

int Boardmax = (Boardmin + 15);
int LNadd = (address,DEC);
if ((LNadd >= Boardmin) and (LNadd <= Boardmax))
Serial.println(“Address >< test passed”); //visual verification on serial monitor
if ((LNadd = Boardmin +1) and (LNstat == 16))
digitalWrite(outP02 , HIGH);
Serial.println(“Output P02 is high”); // again a bit of visual verification on serial monitor
else if ((LNadd = Boardmin +1) and (LNstat == 0 ))
digitalWrite(outP02 , LOW);
Serial.println(“Output P02 is Low”);
digitalWrite(outP04 , HIGH);
Serial.println(“Output P04 is high, nothing else fitted the if criteria”);


// Print Values to serial screen for fault finding / code checking.
// Serial.println(“failed if test”);
Serial.print(“LNadd in outputest :”);
Serial.print(" Board min : “);
Serial.print(” Boardmax : ");
} // end of outputtest()


 int LNadd = (address,DEC);

Why are you abusing the comma operator? Explain what you are trying (but failing) to accomplish with this code.

Hi, sorry the (LNadd, DEC) was an attempt to force the value to a decimal rather than a Hex, found in on the web some were, gave it a try. Its also part of the original Loconet code.

I found it didn't make any difference, shoud have pulled it out before posting. Thats the problem when you frustrated you start clutching at straws.....

But still leaves the issue of why the "if" statement wont resolve, I have had this line in and out doesn't make any diff either way.

Which should you be using, if(x=y) or if(x==y)?

Hi, sorry the (LNadd, DEC) was an attempt to force the value to a decimal rather than a Hex, found in on the web some were, gave it a try.

Sorry, that doesn't make sense. The value stored in the memory location referred to by the name address is stored in binary. The value in memory referred to by the name LNadd will be stored in binary.

the line I am trying to get to resolve that wont is.
if ((LNadd >= Boardmin) and (LNadd <= Boardmax))

Basically I am trying to test if LNadd is greater than or equal to Boardmin, but less than or equal to Boardmax.
The address range is 16 numbers apart in this instance.
so long as the incoming address matches these one of these 16 numbers I want the board to take executive action on the corresponding output pin.


Hi, sorry the (LNadd, DEC) was an attempt to force the value to a decimal rather than a Hex, found in on the web some were, gave it a try.

Instead of writing random moronic garbage, and expecting it to work, you might waste less of your time if you study a basic textbook or online tutorial for C/C++.

I have no idea if you got that from a print( ) function call or some other computer language, but it is nonsense.

if ((LNadd = Boardmin +1) and (LNstat == 16))
else if ((LNadd = Boardmin +1) and (LNstat == 0 ))

See if you can figure out what is wrong with these.

and = && ? - Scotty

They say that "and" is now a valid alternative to "&&"