⚡
usefultools.dev
map

Arduino map() Calculator

NOVO

Arduino map() calculator: see the exact integer result of map(value, fromLow, fromHigh, toLow, toHigh) next to the float value, with a sweep table and code.

Funciona 100% no seu navegador — o que você insere nunca é enviado nem armazenado nos nossos servidores.

Esta ferramenta ainda não está totalmente traduzida, por isso parte do texto continua em inglês. A ferramenta funciona da mesma forma em todos os idiomas.

Arduino map() (long)
127
Exact float result
127.6246
With constrain()
127
(value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow
= (512 - 0) * (255 - 0) / (1023 - 0) + 0
= 130560 / 1023 + 0
= 127 + 0   (division truncates toward zero)
= 127

Sweep table

valuemap()floatlost
0000
1022525.42520.4252
2055151.09970.0997
3077676.52490.5249
409101101.95010.9501
512127127.62460.6246
614153153.04990.0499
716178178.47510.4751
818203203.90030.9003
921229229.57480.5748
10232552550

“lost” = fractional part discarded by integer division. With 0–1023 → 0–255, only an input of exactly 1023 reaches 255; map(x, 0, 1024, 0, 256) spreads the output evenly.

Arduino code

// Integer map(): 0..1023 -> 0..255
void setup() {
  Serial.begin(9600);
}

void loop() {
  long raw = analogRead(A0);            // or any input value
  long out = map(raw, 0, 1023, 0, 255);
  out = constrain(out, 0, 255);   // map() does not clamp

  // Float version (no truncation):
  float outF = (raw - 0) * (float)(255 - 0) / (1023 - 0) + 0;

  Serial.print(out);
  Serial.print('\t');
  Serial.println(outF, 2);
  delay(200);
}
⚡

Exemplos rápidos

Entradas típicas e os resultados que esta ferramenta gera.

ADC → PWM
map(512, 0, 1023, 0, 255)
127 (float 127.6246)
Reversed
map(300, 0, 1023, 255, 0)
181 (float 180.2199)
Out of range
map(1100, 0, 1023, 0, 100)
107 (not clamped)
Negative
map(-50, 0, 1023, 0, 255)
-12 (truncated)
📖

Visão geral

Arduino’s map() function rescales a number from one range to another, for example a 0–1023 analogRead() value to a 0–255 PWM duty or a 0–180 servo angle. It looks like simple proportion math, but it runs on 32-bit long integers: the fraction is thrown away, results are truncated toward zero, and values outside the input range are extrapolated instead of clamped.

This Arduino map calculator reproduces that integer behaviour exactly and shows the floating-point result beside it, so you can see how much precision is lost and why the top value is so hard to reach. A sweep table lists the output across the whole input range, a warning appears when the multiplication would overflow a long, and a ready-to-paste sketch shows both the map() call and a constrain() guard. Everything runs locally in your browser.

Por que usar esta ferramenta?

  • Matches Arduino’s integer map() result exactly
  • Shows the precision lost to truncation
  • Catches 32-bit long overflow before you flash
  • Generates map() plus constrain() code
  • Works offline in your browser, no sign-up
⭐

Recursos

🔢

Exact integer math

Emulates 32-bit long arithmetic with truncating division, reversed ranges and negative values.

📈

Float comparison

Shows the real-valued result and the fractional part map() discards.

📋

Sweep table

Lists 2–101 evenly spaced inputs across fromLow..fromHigh with their outputs.

⚠️

Overflow & range warnings

Flags long overflow and inputs outside the source range that map() will not clamp.

🧩

Code snippet

Copy a sketch with map(), an optional constrain() and a float alternative.

⚡

Live presets

One-click presets for ADC to PWM, percent, servo angle and reversed ranges.

🛠️

Como usar

1

Enter the five arguments

Type value, fromLow, fromHigh, toLow and toHigh, or pick a preset.

2

Read both results

Compare the Arduino map() result with the exact float value and the constrained value.

3

Check the sweep

Set the number of rows to see how the output steps across the range.

4

Copy the code

Toggle constrain() and copy the generated sketch into the Arduino IDE.

🤔

Perguntas frequentes