One caveat would be when mapping an input that ranges from 0 to 1023, since the Arduino is incapable of reading outside of this range there would be no need to constrain. You can check this by running through each iteration from 0 to 1023 and outputting the corresponding mapped value:
for (int i = 0; i < 1024; i++){
Serial.print(i);
Serial.print(",");
Serial.println(map(i, 0, 1023, 0, 255));
}
Certainly, if your sensor reading offers a range smaller than 0 to 1023, then the constrain() function is definitely required, as per LoganBlade's example. Otherwise, it is not needed, but may still fall into the realm of best practice.
The only hiccup to this logic would be if you are mapping to decimal values (which doesn't make much sense since the function will return a long type anyway), in which case the Arduino's internal typecasting will round-down your lowest value mapping. Example:
map(0, 0, 1023, 8.9, 61.9));
>> 0 becomes 8
map(1023, 0, 1023, 8.9, 61.9));
>> 1023 becomes 61
Again, for the sake of best practice and the potential time wasted trying to find a mapping bug, using constrain() is better than skipping it.
s1_min
ands1_max
the guaranteed or the expected limits of the raw reading?map()
does not constrain its output.