@Kuto, have you got it working already?
If not I’d have some suggestion to make.
I must admit I’ve only skimmed over previous posts, but one thing sprang to my attention.
You do this const float ratioV = (120000 + 33000) / 33000;
and assume it works out to 4.636363
.
But have you actually tested this?
Since all your number literals are of integer type, your result might be of integer 4
which gets stored in your float.
Try this instead
const float ratioV = (120000.0 + 33000.0) / 33000.0;
Just a guess without having tried it, but out of old C experience, this does happen
map()
might be viable in some cases, but it also only uses integer math, so if you need fractions, you’d either need to scale your values by x10, x100, x1000 or do your own float version like this
float mapfloat(floar val, float in_min, float in_max, float out_min, float out_max)
{
if(in_max == in_min) // avoid div/zero
return 0;
else
return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}