map() not working as expected

thermalhound:

int distMap = map(dist, 5, 125, 0, 24);

If someone could explain what I've done wrong, or where my understanding is lacking, I would most grateful.

I think the problem is that most people assume that the output of that map() call will always be a number from 0 to 24. That is true ONLY if the input is in the range 5 to 125. If the input is outside that range the output is likely to be outside the expected range as well. For example:

map(300, 100, 200, 0, 1000);

This will return 2000 because 300 is 100% greater than the high end of the input range and 2000 is 100% greater than the high end of the output range.