Go Down

Topic: map function...have to keep invoking it?? (Read 575 times) previous topic - next topic

cyborgcnc

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?

lloyddean

#1
Apr 20, 2012, 07:42 pm Last Edit: Apr 20, 2012, 08:14 pm by lloyddean Reason: 1
"... do I have to keep remapping it..."

Yes.

loop {
    volts_value = map(analogRead(A7), 0, 1023, 0, 5);
    ...
}

AWOL

Bit of a waste of time passing a float to map.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Arrch


or is the code smart enough to ...

For future reference, the answer to this question 99% of the time is going to be no.

cyborgcnc


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!

CrossRoads

"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.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

James C4S


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?
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Go Up