jsolarski 94 Posted August 23, 2010 Share Posted August 23, 2010 Simple mapping function, used to "map" a value from one set of numbers to another. has been very use-full for mapping analog sensor readings to a usable range of numbers. its helped me in the past for a range of different projects /* http://arduino.cc/en/Reference/Map map is taken from the Arduino.cc site value: the number to map fromLow: the lower bound of the value's current range fromHigh: the upper bound of the value's current range toLow: the lower bound of the value's target range toHigh: the upper bound of the value's target range Returns The mapped value. Example: Map an analog value to 8 bits (0 to 255) void loop() { int val = analogRead(0); val1 = map(val2, 0, 1023, 0, 255); analogWrite(9, val); } */ long map(long x, long in_min, long in_max, long out_min, long out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } Quote Link to post Share on other sites
bluehash 1,581 Posted August 23, 2010 Share Posted August 23, 2010 Thats a very handy function when you try to map ADC values to real world engineering values. Thanks for sharing! Quote Link to post Share on other sites
gatesphere 45 Posted August 25, 2010 Share Posted August 25, 2010 Hey jsolarski, do you mind if I include your function into my Arduino-like function library for the MSP430? I'm calling it MSPhere, and releasing it under the GPL once it's in a usable state. Quote Link to post Share on other sites
jsolarski 94 Posted August 25, 2010 Author Share Posted August 25, 2010 go for it use it all you want, i actually used it from the arduino library and is open source, so please if you include it to give credit to the arduino website that i had borrowed it from let me know when you finish your functions Quote Link to post Share on other sites
gatesphere 45 Posted August 25, 2010 Share Posted August 25, 2010 Yeah, I just saw that on the Arduino site. My b. Check my blog for an update, I just posted some info about it. I'm also going to start a new thread for it. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.