I think if(x<val<=y) type of condition checking is supported in arduino
If you really want this check you can write it as:
if (x < val && val <= y)
The code you wrote was a mathematical expression but in C/C++ (as used on the arduino) you have to use binary expressions (i.e. only two values to an operator. So to implement what you want needs three bits (x < val), (val <= y) and &&. The && is C's logical and operator combining the two comparisons.
BTW the code I posted in reply #3 is much more efficient that your original (see below) as you are performing many more comparisons that is necessary. In the first else if
you have already performed the 312 < val
in the preceding if
(as val <= 312 is the opposite of 312 < val) so this part of the expression will always be true if it is executed (a waste of clock cycles and code memory). It is the same for each else if
. This final else if
if should be replaced by an else
as the analog read will produce a value between 0 - 1023 (so the test in this expression will always be true).
As a side issue: if val
was not limited to the range 0 - 1023, for values outside this range tem
would be uninitialised. When I initialise a variable in a if/else if ladder, I always have an else or initialise the variable before the first if.
if (val <= 312)
tem = map(val, 0, 312, 700, 400);
else if(312 < val && val <= 455)
tem = map(val, 312, 455, 400, 300);
else if (455 < val && val <= 612)
tem = map(val, 455, 612, 300, 200);
else if (612 < val && val <= 745)
tem = map(val, 612, 745, 200, 100);
else if(745 < val && val <= 1023)
tem = map(val, 745, 1023, 100, 0);
Hope that helps.