bbcmicrobit / micropython

Port of MicroPython for the BBC micro:bit
https://microbit-micropython.readthedocs.io
Other
595 stars 287 forks source link

`microbit.scale()` to return a float if the arguments for the `to` parameter are floats. #770

Closed microbit-carlos closed 1 year ago

microbit-carlos commented 1 year ago

This is to mirror the change in V2:

If any of the values inside the tuple for the to paramenter are floats, then microbit.scale() will return a float, otherwise it will return an integer.

For example:

# This Celsius to Fahrenheit conversion will return a float
this_will_return_float = scale(value, from=(0, 100), to=(32.0, 212.0))

# This conversion between the accelerometer output to a 1 byte range will return an integer
this_will_return_int = scale(accelerometer.get_x(), from_=(-2000, 2000), to=(0, 255))
dpgeorge commented 1 year ago

Implemented in 8333ac94285ded5bd7981a9809983a8479d6f1f3