Pages: [1]   Go Down
Author Topic: map function...have to keep invoking it??  (Read 527 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"... do I have to keep remapping it..."

Yes.

loop {
    volts_value = map(analogRead(A7), 0, 1023, 0, 5);
    ...
}
« Last Edit: April 20, 2012, 01:14:52 pm by lloyddean » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26183
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bit of a waste of time passing a float to map.
Logged

"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.

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

or is the code smart enough to ...
For future reference, the answer to this question 99% of the time is going to be no.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 533
Posts: 26934
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"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.
Logged

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.

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6146
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Pages: [1]   Go Up
Jump to: