Arduino map() Calculator
NOUVEAUArduino 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.
Fonctionne à 100 % dans votre navigateur — vos données ne sont jamais envoyées ni stockées sur nos serveurs.
Cet outil n'est pas encore entièrement traduit : une partie du texte est encore en anglais. L'outil lui-même fonctionne de la même façon dans toutes les langues.
(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
| value | map() | float | lost |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 102 | 25 | 25.4252 | 0.4252 |
| 205 | 51 | 51.0997 | 0.0997 |
| 307 | 76 | 76.5249 | 0.5249 |
| 409 | 101 | 101.9501 | 0.9501 |
| 512 | 127 | 127.6246 | 0.6246 |
| 614 | 153 | 153.0499 | 0.0499 |
| 716 | 178 | 178.4751 | 0.4751 |
| 818 | 203 | 203.9003 | 0.9003 |
| 921 | 229 | 229.5748 | 0.5748 |
| 1023 | 255 | 255 | 0 |
“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);
}Exemples rapides
Des entrées typiques et les résultats produits par cet outil.
Présentation
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.
Pourquoi utiliser cet outil ?
- 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
Fonctionnalités
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.
Mode d'emploi
Enter the five arguments
Type value, fromLow, fromHigh, toLow and toHigh, or pick a preset.
Read both results
Compare the Arduino map() result with the exact float value and the constrained value.
Check the sweep
Set the number of rows to see how the output steps across the range.
Copy the code
Toggle constrain() and copy the generated sketch into the Arduino IDE.