Deutsch English |
Modul import: from microbit import *
Global function callsFunction | Action |
reset() | restarts the board (and executes main.py) |
sleep(t) | stops program for ms milliseconds |
temperature() | returns the temperature in degrees celsius (as float)) |
display | object reference (instance) |
set_pixel(x, y, value) | sets the intensity of pixel at position x, y. value in range 0..9 |
clear() | clears all pixels |
show(str) | shows given str on LED display. If str has more than 1 character, the text ist scrolled until the last character becomes visible |
show(img) | show Image img on LED display. If img is bigger than 5x5 pixel, the pixels in range x, y = 0..4 are shown. If img is smaller than 5x5 pixel, the missing pixels are black |
show(list_of_img, delay = 400, loop = False, wait = True, clear = False) | shows all images of the list in a timed sequence. If loop = True ist, the sequence is repeated infinitely. For wati = True the method is blocking, otherwise it returns while the sequence continues in the background. delay is the display time for each image in ms (default: 400). For clear = True, the display is clear after the last image is shown |
scroll(str) | shows str as scrolling text. The last character disappears |
scroll(str, delay = 150, loop = False, wait = True, monospace = False) | show str as scrolling text . If loop = True, the sequence is repeated infinitely. For wait = True the method is blocking, otherwise it returns while the sequence continues in the background. delay is the display time for a single column (default: 150) |
button_a | object reference (instance) of button A |
button_b | object reference (instance) of button B |
is_pressed() | returns True, if the button is down (pressed); otherwise False |
was_pressed() | returns True, if the button was pressed since the last call (or start of the program). Another call returns False, until the button is pressed againd |
Image(str) | creates object reference (instance). str has format "aaaaa:bbbbb:ccccc:ddddd:eeeee:" where a is a number in the range 0..9 and defines the intensity of the pixel, a are values of first line, b of second, etc. |
Image() | creates object reference (instance) with 5x5 pixels and all pixels are turned off |
set_pixel(x, y, value) | sets the intensity of pixel at position x, y. value in range 0..9 |
fill(value) | sets all pixel intensities to the given value (0..9) |
get_pixel(x, y) | returns the intensity of the pixel at position x, y |
shift_left(n) | returns an Image object by shifting the picture left by n columns (inserted columns at the right are turned off) |
shift_right(n) | returns an Image object by shifting the picture right by n columns (inserted columns at the left are turned off) |
shift_up(n) | returns an Image object by shifting the picture up by n rows (inserted rows at the bottom are turned off) |
shift_down(n) | returns an Image object by shifting the picture down by n rows (inserted rows at the top are turned off) |
copy() | returns a clone of the image |
invert() | returns an Image object by inverting the intensity of all pixels (new_value = 9 - value) |
image_new = image * n | returns an object with all pixel intensities multiplied by n |
image_new = image1 + image2 | returns an object by adding the pixel intensities of image1 and image2 |
Predefined images:
Example: display.show(Image.SMILE)
pin0, pin1, pin2, pin8, pin12, pin16 | instances for general digital-in/digital-out |
pin0, pin1, pin2 | Instanzen für Analog-in/Analog-out (PWM) |
pin3, pin4, pin6, pin7, pin9, pin10 | instances predefined for LED display (display mode) |
pin5, pin11 | instances predefine for button A, B (button mode) |
pin13, pin14, pin15 | instances predefined for SPI (spi mode) |
pin19, pin20 | instances predefined for I2C (i2c mode) |
read_digital() | returns True, if the pin is logical 1 (HIGH); returns False, if logical 0 (LOW) (Pulldown 10 kOhm) |
write_digital(v) | if v = 1, sets the pin to logical 1 (HIGH); if v = 0, sets the pin to logical 0 (LOW) (max. current: 5 mA) |
read_analog() | returns value from ADC in range 0..1023 (input impedance: 10 MOhm) |
write_analog(v) | setzt den PWM Duty Cycle (v = 0..1023 entsprechend 0..100%) (max. Strom: 5 mA) |
set_analog_period(period) | setzt die PWM-Periode in Millisekunden |
set_analog_period_microseconds(period) | sets the PWM duty cycle (v = 0..1023 corresponds to 0..100%) (max. current: 5 mA) |
accelerometer | object reference (instance) |
get_x(), get_y(), get_z() | returns the current value of acceleration in x, y or z direction (int, range approx.. -2047 to +2048, corresponding approx. -20 m/s^2 to +20 m/s^2, gravitational acceleration of approx. 10 m/s^2 included). x direction: ButtonA-ButtonB; y direction: Pin2-USB; z direction: perpenticular to the board |
get_values() | returns a tuple with the acceleration in x, y and z direction (ints, units as above) |
current_gesture() | returns the current gesture. The following gestures are detected: " up", " down", " left", " right", " face up", " face down", " freefall", " 3g", " 6g", " 8g", " shake" |
compass | object reference (instance) |
calibrate() | starts a blocking calibration routine needed to get accurate readings: tilt the micro:bit in different directions, so that the blinking pixel reaches the border, where the border pixel is turned on. When all border pixels are lit, the program continues |
is_calibrated() | returns True, if the compass was calibrated |
clear_calibration() | resets the compass to the non-calibrated state |
heading() | returns the angle of the current direction if the micro:bit with respect to the north |
get_x(), get_y(), get_z() | returns the current value of the x, y or z component of the magnetic field at the sensor position (int, in microtesla, no calibration needed) |
get_values() | returns a tuple with x , y and z components of the magnetic field at the sensor position (int, in microtesla, no calibration needed) |
np = NeoPixel(pin, n) | creates a Neopixel object (instance) with n neopixels controlled via given pin. Each pixel is addressed by its position (starting from 0) and its color is determined by assigning a RGB tuple, e.g. np[2] = (0, 100, 255) sets pixel # 2 to red = 0, green = 100, blue = 255. show() must be called to update the display (Strips with WS2812 LEDs supported.) (Strips with WS2812 LEDs supported.) |
show() | shows the pixels. Must be called to make any change of color values visible |
clear() | clears all pixels |
Modul music
Modul import: from music import *
Functions:
set_tempo(bpm = 120) | sets the number of beats per minute (default: 120)) |
pitch(frequency, len, pin = microbit.pin0, wait = True) | plays a tone with given frequency in Hertz during the given length (duration) (in milliseconds). pin defines the output pin at the GPIIO header (default: P0). If wait = True, the function is blocking; otherwise it returns while the sound continues (until finished or stop() is called) |
play(melody, pin = microbit.pin0, wait = True, loop = False) | plays a melody with current tempo. pin defines the output pin at the GPIIO header (default: P0). If wait = True, the function is blocking; otherwise it returns while the sound continues (until finished or stop() is called). If loop is True, the melody is played again infinitely |
stop(pin = microbit.pin0) | stops sound output at given header pin (default: P0) |
Remark:
A melody is a list of strings in the format ["note:duration", "note:duration",...] note in musical notation: c, d, e, f, g, a, h with optional octave number (default: 1): e.g. c2, d2, ... and optional sharp: c#, d#,... or c#2, d#2,... duration in number of ticks (optional, defaut: 1)
Predifined song lists
Modul radio:
Modul import: from radio import *
Computer communication over Bluetooth
on() | turns Bluetooth communication on. Connecting to a micro:bit node that has radio turned on |
off() | turns Bluetooth communicaion off |
send(msg) | sends the message string to the receiving node's message queue (First-In-First-Out, FIFO buffer) |
msg = receive() | returns the oldest message (string) in the message queue and removes it from the queue. None is returned, if the queue is empty. It is assumed that the messages is sent with send(smg), so it can be converted in a valuable string [otherwise a ValueError exception ("received packet is not a string") is raised] |
send_bytes(msg_bytes) | sends the message bytes (class bytes, e.g b'\x01\x48') to the receiving node's message queue (First-In-First-Out, FIFO buffer) |
receive_bytes() | returns the oldest message bytes from the message queue and deletes it from the queue. None is returned, if the queue is empty. To send the message, send_bytes(msg) must be used (and not send(msg)) |
Modul mbglow:
Modul import: from mbglow import *
makeGlow() | creates a visible glowbug at position (0, 0) directed to the north with its trace enabled. Coordinate system: -2 <=x <=2 (+ to the right), -2 <= y <= 2 (+ upwards), (0, 0) at center pixel |
forward() | moves the glowbug one step in the forward direction |
back() | moves the glowbug one step in the backward direction |
left(angle) | turns the glowbug in 45 degrees increments to the left (angle = 45, 90, 135, 180, 215, 270, 315) |
right(angle) | turns the glowbug in 45 degrees increments to the right (angle = 45, 90, 135, 180, 215, 270, 315) |
setPos(x, y) | sets the glowbug at position (x, y) |
getPos() | returns the current position of the glowbug (as tuple) |
setSpeed() | sets the speed for movements (0..100) |
clear() | clears all visible pixels. The glowbug remains at the current position (but is invisible) |
showTrace(False) | enables/disables the trace for the following movements (pixels are turned on at the glowbug position) |
isLit() | returns True, if the pixel at the current glowbug position is turned on |
Modul time
Modulimport: import time
Function | Action |
time.time() |
returns the current time in seconds |
Modul sht
(Sensirion temperature and air humidity sensor at I2C port)
Modul import: import sht
sht.getValues() | returns a tuple with temperature (in degrees Celsius) and and humidity (in percent). I2C address: (SHT31: 0x44, SHT35: 0x45) |
Modul sgp
SGP30 Air Quality Sensor (Co2-Sensor at I2C-Port)
Modul import: import sgp
sgp.getValues() | returns a tuple with CO2 koncentration (in ppm) and VOC (Total Volantile Organic Compunds). The sensor is calibrated to CO2 = 400. Ventilation is urgently required for values higher than 1000. I2C address (SGP30: 0x58) |