Microbit Module¶
The microbit
module gives you access to all the hardware that is built-in
into your board.
Functions¶
-
microbit.
panic
(n)¶ Enter a panic mode that stops all execution, scrolls an error code in the micro:bit display and requires restart:
microbit.panic(255)
Parameters: n – An arbitrary integer between 0 and 255 to indicate an error code.
-
microbit.
reset
()¶ Restart the board.
-
microbit.
running_time
()¶ Returns: The number of milliseconds since the board was switched on or restarted.
-
microbit.
scale
(value, from_, to)¶ Converts a value from a range to another range.
For example, to convert 30 degrees from Celsius to Fahrenheit:
temp_fahrenheit = scale(30, from_=(0, 100), to=(32, 212))
This can be useful to convert values between inputs and outputs, for example an accelerometer x value to a speaker volume.
Negative scaling is also supported, for example
scale(25, from_=(0, 100), to=(0, -200))
will return-50
.Parameters: - value – A number to convert.
- from – A tuple to define the range to convert from.
- to – A tuple to define the range to convert to.
Returns: The
value
converted to theto
range.
-
microbit.
sleep
(n)¶ Wait for
n
milliseconds. One second is 1000 milliseconds, somicrobit.sleep(1000)
will pause the execution for one second.Parameters: n – An integer or floating point number indicating the number of milliseconds to wait.
-
microbit.
temperature
()¶ Returns: An integer with the temperature of the micro:bit in degrees Celcius.