ok does sensor.distance.in work to get the answer in inches? you only state sensor.distance.cm in the documentation.
No - you can only ready cm.
Keep meaning to get round to a global conversion suite ie
cm <=> inches
cm <=> feet
etc
So if you want to convert cm to inches for now then divide the result by 2.54 or multiply by 0.3937
Of course this requires floating point maths which makes your program bigger if you are not using floating point elsewhere in your program.
If you want to avoid floating point use my Fibonacci calculator here:
http://www.societyofrobots.com/fibonnaci_series_calculator.shtmlYou will see the 10 bit approximation for 0.3937 is: 1/3 + 1/17 + 1/693
So add this to your code:
#include "fraction.h"
const uint16_t PROGMEM frac_cm_to_in[] = { 0, 3, 17, 693, 0};
To convert the value in cm to inches you can use:-
DISTANCE_TYPE cm = sensor.distance.cm;
DISTANCE_TYPE inches = fraction32(cm, frac_cm_to_in );
You now have a value in inches
Edit:
The reason why sensor.distance.in can't work is that this is accessing a variable. So as well as cm, I would also need to compute the value for inches, feet, meters etc etc every time as well as requiring the RAM to store these conversions. Too much overhead. Hence using 'cm' which is the least common denominator and sensors aren't accurate enough to return 'mm'.
Perhaps, in a later release, once I've done that scaler functions to convert between different scales then I could have routines like
distanceSensorInCM(sensor);
distanceSensorInInches(sensor);
etc
But thats all for the future at the moment.