system
April 20, 2012, 5:39pm
1
Another question for the kind folks here:
say I have something like this:
float read_volts = analogRead (A7);
int volts_value = map (read_volts, 0, 1023, 0, 5);
rest of my program....blah blah....now need to take another reading...
loop {
read_volts = analogRead (A7);
blah blah
}
do I have to keep remapping it, or is the code smart enough to figure out to map it, since I already told it to do so say out side some loop?
in other words is the mapping "global" define it once and done? or have to keep remapping each time a reading is taken?
"... do I have to keep remapping it..."
Yes.
loop {
volts_value = map(analogRead(A7), 0, 1023, 0, 5);
...
}
system
April 20, 2012, 6:56pm
3
Bit of a waste of time passing a float to map.
Arrch
April 20, 2012, 7:53pm
4
cyborgcnc:
or is the code smart enough to ...
For future reference, the answer to this question 99% of the time is going to be no.
system
April 20, 2012, 8:32pm
5
AWOL:
Bit of a waste of time passing a float to map.
so what do you suggest, just keep working with the raw float values out of the analog ports?, ie do not bother with the mapping at all?
thanks!
"read_volts = analogRead (A7);" will return an int, not a float. 0 to 1023.
float volts_value;
volts_value = read_volts * 5/1023; // no mapping needed.
cmiyc
April 20, 2012, 8:58pm
7
cyborgcnc:
so what do you suggest, just keep working with the raw float values out of the analog ports?, ie do not bother with the mapping at all?
What lead you to believe the integer values from an analogRead were float?