Hide minor edits - Show changes to output

August 24, 2012, at 11:51 PM
by

- Changed line 40 from:

[@

to:

(:source lang=arduino:)

Changed lines 50-52 from:

@]

to:

(:sourceend:)

February 06, 2010, at 09:26 AM
by

- Changed lines 70-72 from:

* [[Mathh|math.h]]

to:

February 06, 2010, at 03:20 AM
by

- Changed lines 69-70 from:

* [[constrain]]()

to:

* [[constrain]]()

* [[Mathh|math.h]]

* [[Mathh|math.h]]

August 04, 2008, at 09:03 PM
by

- Changed lines 13-15 from:

The function also handles negative numbers well so

this example

this example

to:

The function also handles negative numbers well, so

that this example

that this example

August 04, 2008, at 05:55 AM
by

- Changed lines 16-17 from:

[@ y = map(x, 1, 50, -50, -100); @]

to:

[@ y = map(x, 1, 50, 50, -100); @]

August 04, 2008, at 05:55 AM
by

- Changed lines 38-39 from:

!!!!Examples

to:

!!!!Example

Added line 41:

/* Map an analog value to 8 bits (0 to 255) */

August 04, 2008, at 05:53 AM
by

- Added line 10:

August 04, 2008, at 05:51 AM
by

- Changed lines 19-20 from:

The map() function uses integer math so will not generate fractions, when the math might indicate that is should do so. Fractional remainders are truncated, and are not rounded or averaged.

to:

The map() function uses integer math so will not generate fractions, when the math might indicate that it should do so. Fractional remainders are truncated, and are not rounded or averaged.

Deleted lines 64-67:

August 04, 2008, at 05:50 AM
by

- Changed lines 7-9 from:

Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The constrain function may be used either before or after this function if constrained ranges are desired.

Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the function may be used to reverse a range of numbers, for example

Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the function may be used to reverse a range of numbers, for example

to:

Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The constrain() function may be used either before or after this function, if limits to the ranges are desired.

Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the map() function may be used to reverse a range of numbers, for example

Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the map() function may be used to reverse a range of numbers, for example

August 04, 2008, at 05:47 AM
by

- Changed lines 50-54 from:

Note that the lower and upper bounds are just markers that define the ranges

to:

August 04, 2008, at 05:47 AM
by

- Added lines 9-20:

Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the function may be used to reverse a range of numbers, for example

[@ y = map(x, 1, 50, 50, 1); @]

The function also handles negative numbers well so

this example

[@ y = map(x, 1, 50, -50, -100); @]

is also valid and works well.

The map() function uses integer math so will not generate fractions, when the math might indicate that is should do so. Fractional remainders are truncated, and are not rounded or averaged.

[@ y = map(x, 1, 50, 50, 1); @]

The function also handles negative numbers well so

this example

[@ y = map(x, 1, 50, -50, -100); @]

is also valid and works well.

The map() function uses integer math so will not generate fractions, when the math might indicate that is should do so. Fractional remainders are truncated, and are not rounded or averaged.

Added lines 49-54:

Note that the lower and upper bounds are just markers that define the ranges

August 04, 2008, at 05:30 AM
by

- Changed lines 7-8 from:

Does not constrain values to within the range, because out-of-range values are sometimes intended and useful.

to:

Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The constrain function may be used either before or after this function if constrained ranges are desired.

Changed lines 25-26 from:

!!!!Example

to:

!!!!Examples

Changed lines 37-38 from:

!!! Apendix

to:

!!! Appendix

August 03, 2008, at 08:35 PM
by

- Deleted line 36:

August 03, 2008, at 08:34 PM
by

- Added lines 38-55:

!!! Apendix

For the mathematically inclined, here's the whole function

[@

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;

}

@]

For the mathematically inclined, here's the whole function

[@

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;

}

@]

April 23, 2008, at 06:44 AM
by

- Changed lines 7-8 from:

Does not constrain values to within the range, because out-of-range values are something intended and useful.

to:

Does not constrain values to within the range, because out-of-range values are sometimes intended and useful.

March 29, 2008, at 03:31 PM
by

- Added lines 25-37:

!!!!Example

[@

void setup() {}

void loop()

{

int val = analogRead(0);

val = map(val, 0, 1023, 0, 255);

analogWrite(9, val);

}

@]

[@

void setup() {}

void loop()

{

int val = analogRead(0);

val = map(val, 0, 1023, 0, 255);

analogWrite(9, val);

}

@]

March 29, 2008, at 03:15 PM
by

- Added lines 1-27:

!!map(value, fromLow, fromHigh, toLow, toHigh)

!!!!Description

Re-maps a number from one range to another. That is, a '''value''' of '''fromLow''' would get mapped to '''toLow''', a value of '''fromHigh''' to '''toHigh''', values in-between to values in-between, etc.

Does not constrain values to within the range, because out-of-range values are something intended and useful.

!!!!Parameters

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.

!!!!See Also

* [[constrain]]()

!!!!Description

Re-maps a number from one range to another. That is, a '''value''' of '''fromLow''' would get mapped to '''toLow''', a value of '''fromHigh''' to '''toHigh''', values in-between to values in-between, etc.

Does not constrain values to within the range, because out-of-range values are something intended and useful.

!!!!Parameters

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.

!!!!See Also

* [[constrain]]()