Closed
Description
A function like this is quite useful to be able to map inputs an outputs with different value ranges.
For example the output from one sensor to an LED brightness value, sound level, or sound effect attribute.
Arduino, and MakeCode have a map()
function with the same argument order, so it'd be good to follow the convention:
map(value, fromLow, fromHigh, toLow, toHigh)
Although it's tempting to try to improve it:
map(value, from=(low,high), to=(low, high))
Would that be better? I personally don't feel strongly either way.
Options for the name
map()
andrange()
are already taken in Python, so we shouldn't shadow themtransform()
is a tiny bit longer and not very clear what it might bescale()
seems like a good word
Where to we put the function?
- It's probably not a good idea to add it globally
- The easiest place for users to find it is inside the
microbit
module, as many programmes dofrom microbit import *
- It would kind of make sense to have it inside the
math
module, but that would divert from the CPython implementation and we should probably avoid that- Diverting from "generic" MicroPython's
umath
is probably also undesirable?
- Diverting from "generic" MicroPython's
- It might not be worth creating a new module just for this unless we had more stuff to put in it