Hello people, I am a newbie in coding and need to map an analog input (potentiometer) to output decimal value from 0.00 to 10.00.
Currently I have:
mA=map(current, 0,255,0,10);
But I would need more precision, basically the equivalent of:
mA=map(current, 0,255,0.00,10.00);
I have learnt that the map() function uses integer math so will not generate fractions.
What would be the codes to get the equivalent of
mA=map(current, 0,255,0.00,10.00);
Cheers
Is the input really 0 to 255 or is it 0 to 1023 ?
gcjr
4
ma = 10.0 * current / 255;
but shouldn't 255 be 1023
Maybe he is confusing analogRead() with analogWrite(). We won't know unless we ask
Right it is in fact 0 - 1023...
Yep, that worked...
I used
float mA=map(current, 0,1023,0,1000) / 100.0;
Cheers
1 Like
gcjr
12
either value is probably good enough close enough.
if you want to know for sure, here's what the part does
of course there's a big difference between 255 and 1023/1024
system
Closed
13
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.