The more than 30 mBuild modules and supporting parts can meet your needs for electronic modules in various scenarios, including making your creative ideas come to life, comprehensive practice, project-based eduction, porgramming popularization, AI popularization, and robotics competitions.

Artboard 1@2x.jpg


Note: To use the functions of mBuild modules, you need to purchase the corresponding mBuild add-on kits or packs.


mBuild modules support multiple main control boards and can work with them through different Python API libraries, with the same functions.


Import the corresponding API library when using mBuild modules with a main control board. In addition, mBuild modules can also be used as a standalone device.


For example, to use mBuild modules through CyberPi, import the cyberpi library.


from cyberpi import *


To use mBuild modules through Halocode, import the halocode library.


from halocode import *


To use mBuild modules as a standalone device, import the mbuild library.


from mbuild import *


Common parameter index

All APIs for mBuild modules include the parameter index, which indicates the place of a module among the ones connected to the main control board. Generally, the default value is 1. Therefore, if only one module of each type is used, you don't need to set this parameter. When two or more modules of the same type are used, you need to set index to 2, 3, 4, or another number to specify the second, third, forth, or another module. For example, motor_driver.set(100, index = 2) indicates that the output power of the second motor driver is set to 100.

Input modules

Interaction Modules

Button

button.is_press(index = 1)

Detects whether the button is pressed.

Returns a Boolean value:

True: button pressed

False: button not pressed


button.get_count(index = 1)

Obtains the number of times the button is pressed after it is powered on.

Returns a numeric value.


button.reset_count(index = 1)

Resets the number of times the button is pressed to zero.


Angle Sensor

angle_sensor.get(index = 1)

Obtains the angle the angle sensor rotates (relative to the position it is located when being powered).

Returns a numeric value in degrees (°). The value is increased when the angle sensor rotates clockwise and is reduced when it rotates anticlockwise.


angle_sensor.reset(index = 1)

Resets the angle the angle sensor rotates.


angle_sensor.get_speed(index = 1)

Obtains the speed at which the angle sensor rotates.

Returns a numeric value in degrees per second (°/s). The value is positive when the angle sensor rotates clockwise and is negative when it rotates anticlockwise.


angle_sensor.is_clockwise(index = 1).

Detects whether the angle sensor is rotating clockwise.

Returns a Boolean value:

True: rotating clockwise

False: not rotating clockwise


angle_sensor.is_anticlockwise(index = 1)

Detects whether the angle sensor is rotating anticlockwise.

Returns a Boolean value:

True: rotating anticlockwise

False: not rotating anticlockwise


Slider

slider.get(index = 1)

Obtains the position of the slider.

Returns a numeric value ranging from 0 to 100, in percentage (%).

It indicates the position of the slider.


Joystick

joystick.get_x(index = 1)

Obtains the output value of the joystick at the x axis.

Returns a numeric value ranging from –100 to +100.


joystick.get_y(index = 1)

Obtains the output of the joystick at the y axis.

Returns a numeric value ranging from –100 to +100.


joystick.is_up(index = 1)

Determines whether the joystick pivots upwards.

Returns a Boolean value:

True: pivoting upward

False: not pivoting upward


joystick.is_down(index = 1)

Determines whether the joystick pivots downward.

Returns a Boolean value:

True: pivoting downward

False: not pivoting downward


joystick.is_left(index = 1)

Determines whether the joystick pivots towards the left.

Returns a Boolean value:

True: pivoting towards the left

False: not pivoting towards the left


joystick.is_right(index = 1)

Determines whether the joystick pivots towards the right.

Returns a Boolean value:

True: pivoting towards the right

False: not pivoting towards the right


Multi Touch

multi_touch.is_touch(ch = "any", index = 1)

Detects whether the specified touch sensor of Multi Touch is touched. The Multi touch module detects objects through the capacitance change of touch sensors. Therefore, with proper threshold settings, it can detect the touching through paper, wooden boards, plastics, or other insulators. The approaching of a conductor, after all, changes the capacitance of a touch sensor.

Parameters:

Returns a Boolean value:

True: touched

False: not touched


multi_touch.reset(level = "middle", index = 1)

Sets the threshold for Multi Touch.

Parameters:


Sensors

Quad RGB Sensor

image.png

quad_rgb_sensor.get_line_sta(index = 1)

Obtains the state of the line to be followed.

Returns an integer that ranges from 0 to 15, corresponding to the binary numbers 0000 to 1111, where 1 indicates that the background color (light color by default) is detected and 0 indicates that the line (dark color by default) is detected.


The following table describes the possible returned values and the corresponding line states.

Returned value

Binary number

Line state detected

(Dark line on a light background)

0

0000

image.png

1

0001

image.png

2

0010

image.png

3

0011

image.png

4

0100

image.png

5

0101

image.png

6

0110

image.png

7

0111

image.png

8

1000

image.png

9

1001

image.png

10

1010

image.png

11

1011

image.png

12

1100

image.png

13

1101

image.png

14

1110

image.png

15

1111

image.png


quad_rgb_sensor.get_offset_track(index = 1)

Obtains how much Quad RGB Sensor deviates from the line to be followed.

Returns an integer that ranges from –100 to +100. The deviation of –100 indicates that Quad RGB Sensor is on the left of the line to be followed.


quad_rgb_sensor.is_line(ch, index = 1)

Determines whether a line is detected by the specified sensor.

Parameter:

Value range: "any"/"L2"/"L1"/"R1"/"R2"/"l2"/"l1"/"r1"/"r2"/4/3/2/1

Returns a Boolean value:

True: detected

False: not detected


quad_rgb_sensor.is_background(ch, index = 1)

Determines whether a background is detected by the specified sensor.

Parameter:

Value range: "any"/"L2"/"L1"/"R1"/"R2"/"l2"/"l1"/"r1"/"r2"/4/3/2/1

Returns a Boolean value:

True: detected

False: not detected


quad_rgb_sensor.is_color(color = "white", ch, index = 1)

Determines whether the specified sensor detects the specified color.

Parameters:

red r

yellow y

green g

cyan c

blue b

purple p

white w

black k


Value range: "any"/"L2"/"L1"/"R1"/"R2"/"l2"/"l1"/"r1"/"r2"/4/3/2/1

Returns a Boolean value:

True: detected

False: not detected


quad_rgb_sensor.get_red(ch, index = 1)

Obtains the red color intensity detected by the specified sensor.

Parameter:

Value range: "L2"/"L1"/"R1"/"R2"/"l2"/"l1"/"r1"/"r2"/4/3/2/1

Returns a value that ranges from 0 to 255.


quad_rgb_sensor.get_green(ch, index = 1)

Obtains the green color intensity detected by the specified sensor.

Parameter:

Value range: "L2"/"L1"/"R1"/"R2"/"l2"/"l1"/"r1"/"r2"/4/3/2/1

Returns a value that ranges from 0 to 255.


quad_rgb_sensor.get_blue(ch, index = 1)

Obtains the blue color intensity detected by the specified sensor.

Parameter:

Value range: "L2"/"L1"/"R1"/"R2"/"l2"/"l1"/"r1"/"r2"/4/3/2/1

Returns a value that ranges from 0 to 255.


quad_rgb_sensor.get_gray(ch, index = 1)

Obtains the gay scale detected by the specified sensor.

The value of the gray scale is the difference between the ambient light intensity with the fill light turned on and that without the fill light, directly indicating how well the object reflects light.

Parameter:

Value range: "L2"/"L1"/"R1"/"R2"/"l2"/"l1"/"r1"/"r2"/4/3/2/1

Returns a value that ranges from 0 to 100.


quad_rgb_sensor.get_color(ch, index = 1)

Obtains the hex value of the color detected by the specified sensor.

Parameter:

Value range: "L2"/"L1"/"R1"/"R2"/"l2"/"l1"/"r1"/"r2"/4/3/2/1

Returns a hex value that ranges from 0x000000 to 0xffffff.


quad_rgb_sensor.get_color_sta(ch, index = 1)

Obtains the name (character string) of the color detected by the specified sensor.

Parameter

Value range: "L2"/"L1"/"R1"/"R2"/"l2"/"l1"/"r1"/"r2"/4/3/2/1

Returns a character string that may be:

"red" 
"yellow"
"green"
"cyan" 
"blue"
"purple"
"white"
"black"


quad_rgb_sensor.get_light(ch, index = 1)

Obtains the ambient light intensity detected by the specified sensor.

The light emitted by the fill lights is part of the ambient light. If necessary, you can turn off all the fill lights before using this API.

Parameter:

Value range: "L2"/"L1"/"R1"/"R2"/"l2"/"l1"/"r1"/"r2"/4/3/2/1

Returns a value that ranges from 0 to 100.


quad_rgb_sensor.set_led(color = "white", index = 1)

Sets the color of all fill lights.

Parameter:

To set it to a string, enter the full name or abbreviation of a color; the following describes colors and their abbreviations:

red r

yellow y

green g

cyan c

blue b

purple p

white w

black k

To set it to a hex value, enter the hex value of the color.


quad_rgb_sensor.off_led(index = 1)

Turns off the fill lights.

Note that when the API for detecting colors is executed, the quad RGB sensor automatically sets the fill lights to the color it requires.


Ultrasonic Sensor 2

image.png

ultrasonic2.get(index = 1)

Obtains the distance between an obstacle and ultrasonic sensor 2.

Returns a value that ranges from 3 to 300, in centimeters, with an error of ±5%.


ultrasonic2.led_show(bri, index =1)

Sets the brightness of all the LEDs.

Parameter设置超声波模块氛围灯的亮度。参数:

This parameter must be set in the format of [bri1,bri2,bri3,bir4,bri5,bri6,bri7,bri8], where x indicates the number of an LED.

The following figure shows the LEDs and their numbers.


ultrasonic2.set_bri(led_bri, id, index =1)

Sets the brightness of the specified LED.

Parameters:

int: number of the specified LED, ranging from 1 to 8

str: The value can only be all, indicating all the LEDs.


ultrasonic2.add_bri(led_bri, id, index =1)

Increases the brightness of the specified LED.

Parameters:

int: number of the specified LED, ranging from 1 to 8

str: The value can only be all, indicating all the LEDs.


ultrasonic2.get_bri(id, index =1)

Obtains the brightness of the specified LED.
Parameter:

int: number of the specified LED, ranging from 1 to 8

str: The value can only be all, indicating all the LEDs.


Light Sensor

light_sensor.get(index = 1)

Obtains the output value of the light sensor.

Returns a numeric value ranging from 0 to 100.


Dual RGB Color Sensor

dual_rgb_sensor.is_color(color = "white", ch, index = 1)

Determines whether the color sensor detects the specified color.

Parameters:

red r
yellow y
green g
cyan c
blue b
purple p
white w
black k

Returns a Boolean value:

True: detected

False: not detected


dual_rgb_sensor.get_red(ch = 1, index = 1)

Obtains the R value of the color detected by the color sensor.

Parameters:

Returns a numeric value ranging from 0 to 255.


dual_rgb_sensor.get_green(ch = 1, index = 1)

Obtains the G value of the color detected by the color sensor.

Parameters:


dual_rgb_sensor.get_blue(ch = 1, index = 1)

Obtains the B value of the color detected by the color sensor.

Parameters:

Returns a numeric value ranging from 0 to 255.


dual_rgb_sensor.get_light(ch = 1, index = 1)

Obtains the ambient light intensity detected by the color sensor. The fill light provided by the color sensor is also part of the ambient light. Turn off the fill light before you use this API function, if necessary.

Parameters:

Returns a numeric value ranging from 0 to 100.


dual_rgb_sensor.get_gray_level(ch = 1, index = 1)

Obtains the reflected light intensity detected by the color sensor. The value is the difference between the ambient light intensity detected when the fill light is turned on and that detected when the fill light is turned off.

Parameters:

Returns a numeric value ranging from 0 to 100.


dual_rgb_sensor.set_led(color = "white", index = 1)

Sets the color of the fill light.

Parameters:

red r
yellow y
green g
cyan c
blue b
purple p
white w
black k


dual_rgb_sensor.off_led(index = 1)

Turns off the fill light. Note that the color sensor automatically sets the fill light to the required color when invoking the color detection API function.


Sound Sensor

sound_sensor.get(index = 1)

Obtains the output value of the sound sensor.

Returns a numeric value ranging from 0 to 100.


PIR Sensor

pir.is_detect(index = 1)

Determines whether the PIR sensor detects human movement. The indicator is lit up when the PIR sensor is triggered. It remains in the triggered state for three seconds. It exits from the triggered state and turns off the indicator if it doesn't detect human movement in the subsequent three seconds.

Returns a Boolean value:

True: human movement detected

False: no human movement detected


pir.get_count(index = 1)

Obtains the number of times the PIR sensor is triggered after it is powered on.

Returns a positive integer.


pir.reset_count(index = 1)

Resets the number of times the PIR sensor is triggered to zero.


Ultrasonic Sensor

ultrasonic.get(index = 1)

Obtains the distance between the ultrasonic sensor and obstacle.

Returns a numeric value ranging from 3 to 300, in centimeters (cm), with a deviation of ±5%.


Ranging Sensor

ranging_sensor.get(index = 1)

Obtains the distance between the ranging sensor and obstacle.

Returns a numeric value ranging from 2 to 200, in centimeters (cm), with a deviation of ±5%.


Motion Sensor

motion_sensor.is_shake(index = 1)

Detects whether the motion sensor is shaken.

Returns a Boolean value:

True: shaken

False: not shaken


motion_sensor.get_shakeval(index = 1)

Obtains the strength the motion sensor is shaken.

Returns a numeric value ranging from 0 to 100. A greater value indicates stronger shaking.


motion_sensor.get_accel(axis, index = 1)

Obtains the acceleration at the x, y, or z axis.

Parameters:

Returns a numeric value in meters per second (m/s²).


motion_sensor.is_tiltleft(index = 1)

Detects whether the motion sensor is tilted towards the left. The threshold is 15 degrees.

Returns a Boolean value:

True: tilted towards the left

False: not tilted towards the left


motion_sensor.is_tiltright(index = 1)

Detects whether the motion sensor is tilted towards the right. The threshold is 15 degrees.

Returns a Boolean value:

True: tilted towards the right

False: not tilted towards the right


motion_sensor.is_tiltup(index = 1)

Detects whether the motion sensor is tilted upwards. The threshold is 15 degrees.

Returns a Boolean value:

True: tilted upwards

False: not tilted upwards


motion_sensor.is_tiltdown(index = 1)

Detects whether the motion sensor is tilted downwards. The threshold is 15 degrees.

Returns a Boolean value:

True: tilted downwards

False: not tilted downwards


motion_sensor.is_faceup(index = 1)

Detects whether the motion sensor is placed face up.

True: placed face up

False: not placed face up


motion_sensor.is_facedown(index = 1)

Detects whether the motion sensor is placed face down.

True: placed face down

False: not placed face down


motion_sensor.get_roll(index = 1)

Obtains the rolling angle of the motion sensor.

Returns a numeric value ranging from –90 to +90, in degrees (°).


motion_sensor.get_pitch(index = 1)

Obtains the pitch angle of the motion sensor.

Returns a numeric value ranging from –180 to +180, in degrees (°).


motion_sensor.get_yaw(index = 1)

Obtains the yaw angle of the motion sensor.

Returns a numeric value ranging from 0 to 360, in degrees (°).

Note: No electronic compass is used, and therefore the yaw angle is the integral of the angular speed of the motion sensor at the z axis. Accumulative error may occur. This API function can't be used to obtain the accurate yaw angle.


motion_sensor.get_gyro(axis, index = 1)

Obtains the angular speed of the motion sensor at the x, y, or z axis.

Parameters:

Returns a numeric value in degrees per second (°/s²).


motion_sensor.get_rotation(axis, index = 1)

Obtains the angle the motion sensor rotates at the x, y, or z axis. The angle is positive when the motion sensor is rotated anticlockwise.

Parameters:

Returns a numeric value in degrees(°).


motion_sensor.reset_rotation(axis= "all", index = 1)

Initializes the current angle of the motion sensor at the x, y, and/or z axis as zero. After the initialization, get_rotation() calculates from zero.

Parameters:


Soil Moisture Sensor

soil_sensor.get(index = 1)

Obtains the output value of the soil moisture sensor.

Returns a numeric value ranging from 0 to 100.


Temperature Sensor

temp_sensor.get(index = 1)

Obtains the output value of the temperature sensor.

Returns a numeric value ranging from –55 to +125, in degrees centigrade (℃).


Humiture Sensor

humiture.get_humidity(index = 1)

Obtains the output humidity value of the humiture sensor.

Returns a numeric value ranging from 0 to 100, in percentage (%).


humiture.get_temp(index = 1)

Obtains the output temperature value of the humiture sensor.

Returns a numeric value ranging from –40 to +125, in degrees centigrade (℃).


MQ2 Gas Sensor

mq2.is_detect(level = “high”, index = 1)

Determines whether the density of the detected combustible gas exceeds the threshold.

Parameters:

mq2.get(index = 1)

Obtains the output value of the MQ2 gas sensor.

Returns a numeric value ranging from 0 to 100. A greater value indicates a higher density of combustible gas.


Flame Sensor

flame_sensor.is_detect(index = 1)

Determines whether a flame is detected.

Returns a Boolean value:

True: detected

False: not detected


flame_sensor.get(index = 1)

Obtains the output value of the flame sensor.

Returns a numeric value ranging from 0 to 100.


Magnetic Sensor

magnetic_sensor.is_detect(index = 1)

Determines whether a magnet is detected around the magnetic sensor.

Returns a Boolean value:

True: detected

False: not detected


magnetic_sensor.get_count(index = 1)

Obtains the number of times the magnetic sensor is triggered after it is powered on.

Returns a numeric value.


magnetic_sensor.reset_count(index = 1)

Resets the number of times the magnetic sensor is triggered to zero.


Smart Camera

smart_camera.set_mode(mode = "color", index = 1)

Sets the detection mode of the smart camera.

Parameters:

smart_camera.learn(sign = 1, t = "until_button", index = 1)

Sets the number of the color block to be learned.

Parameters:


smart_camera.detect_sign(sign, index = 1)

Determines whether the specified color block is detected.

Parameters:

Returns a Boolean value:

True: detected

False: not detected


smart_camera.detect_sign_location(sign, location, index = 1)

Determines whether the specified color block is detected in the specified area of the captured image.

Parameters:


image

Returns a Boolean value:

True: detected

False: not detected


smart_camera.get_sign_x(sign, index = 1)

Obtains the x-coordinate of the specified color block in the captured image.

Parameters:

Returns a numeric value ranging from 0 to 319. If the specified color block is not detected, the value 0 is returned.


smart_camera.get_sign_y(sign, index = 1)

Obtains the y-coordinate of the specified color block in the captured image.

Parameters:

Returns a numeric value ranging from 0 to 239. If the specified color block is not detected, the value 0 is returned.


smart_camera.get_sign_wide(sign, index = 1)

Obtains the width of the specified color block in the captured image.

Parameters:

Returns a numeric value ranging from 0 to 319. If the specified color block is not detected, the value 0 is returned.


smart_camera.get_sign_hight(sign, index = 1)

Obtains the height of the specified color block in the captured image.

Parameters:

Returns a numeric value ranging from 0 to 239. If the specified color block is not detected, the value 0 is returned.


smart_camera.open_light(index = 1)

Turns on the two LED fill lights on the smart camera.


smart_camera.close_light(index = 1)

Turns off the two LED fill lights on the smart camera.


smart_camera.reset(index = 1)

Resets the white balance for the smart camera. This API function blocks the process being executed for five seconds.


smart_camera.detect_label(label, index = 1)

Determines whether the specified barcode is detected.

Parameters:

Returns a Boolean value:

True: detected

False: not detected


smart_camera.get_label_x(label, index = 1)

Obtains the x-coordinate of the specified barcode in the captured image.

Parameters:

Returns a numeric value ranging from 0 to 319. If the specified barcode is not detected, the value 0 is returned.


smart_camera.get_label_y(sign, index = 1)

Obtains the y-coordinate of the specified barcode in the captured image.

Parameters:

Returns a numeric value ranging from 0 to 239. If the specified barcode is not detected, the value 0 is returned.


smart_camera.detect_cross(index = 1)

Determines whether an intersection is detected in the captured image.


smart_camera.get_cross_x(index = 1)

Obtains the x-coordinate of the detected intersection.

Returns a numeric value ranging from 0 to 319. If no intersection is detected, the value 0 is returned.


smart_camera.get_cross_y(index = 1)

Obtains the y-coordinate of the detected intersection.

Returns a numeric value ranging from 0 to 239. If no intersection is detected, the value 0 is returned.


smart_camera.get_cross_road(index = 1)

Obtains the number of detected crossroads.

Returns a numeric value.


smart_camera.get_cross_angle(sn = 1, index = 1)

Obtains the angle between the specified crossroad and vector, which is the line where the smart camera is located.

Parameters:

smart_camera.set_line(mode = "black, index = 1)

Sets the color preference for the line tracking mode.

Parameters:


smart_camera.get_vector_start_x(index = 1)

Obtains the start x-coordinate of the vector where the smart camera is located.

Returns a numeric value ranging from 0 to 319.


smart_camera.get_vector_start_y(index = 1)

Obtains the start y-coordinate of the vector where the smart camera is located.

Returns a numeric value ranging from 0 to 239.


smart_camera.get_vector_end_x(index = 1)

Obtains the end x-coordinate of the vector where the smart camera is located.

Returns a numeric value ranging from 0 to 319.


smart_camera.get_vector_end_y(index = 1)

Obtains the end y-coordinate of the vector where the smart camera is located.

Returns a numeric value ranging from 0 to 239.


smart_camera.set_vector_angle(angle, index = 1)

Sets the angle preference for the vector.

Parameters:


smart_camera.get_vector_angle(index = 1)

Obtains the set angle preference.

Returns a numeric value ranging from –180 to +180, in degrees (°).


smart_camera.set_kp(kp, index = 1)

Sets the coefficient Kp for the smart camera to calculate the motor differential speed.

Parameters:


smart_camera.get_sign_diff_speed(sign, axis, axis_val, index = 1)

Calculates the motor differential speed required for keeping the specified color block in the specified x- or y-coordinate of the captured image. The motor differential speed is positively related to Kp. A greater Kp value indicates a greater motor differential speed.

Parameters:

Returns a numeric value ranging from 0 to 100.


smart_camera.get_label_diff_speed(label, axis, axis_val, index = 1)

Calculates the motor differential speed required for keeping the specified barcode in the specified x- or y-coordinate of the captured image. The motor differential speed is positively related to Kp. A greater Kp value indicates a greater motor differential speed.

Parameters:

Returns a numeric value ranging from 0 to 100.


smart_camera.get_follow_vector_diff_speed(index = 1)

Calculates the motor differential speed required for keeping the vector in the center of the captured image. The motor differential speed is positively related to Kp. A greater Kp value indicates a greater motor differential speed.

Returns a numeric value ranging from 0 to 100.


smart_camera.is_lock_sign(sign, axis, axis_val, index = 1)

Determines whether the specified color block is near the specified x- or y-coordinate of the captured image.

Parameters:

Returns a Boolean value:

True: near the specified point

False: not near the specified point


smart_camera.is_lock_label(sign, axis, axis_val index = 1)

Determines whether the specified barcode is near the specified x- or y-coordinate of the captured image.

Parameters:

Returns a Boolean value:

True: near the specified point

False: not near the specified point

Output modules

Light

LED Matrix

led_matrix.show(image = "hi", index = 1)

Sets the image to be displayed on the LED matrix.

Parameters:


image


To display an image that is not predefined, you need to set image to the hexadecimal number corresponding to the image. The hexadecimal numbers are obtained as follows:

Take the on/off state of the eight LEDs on one column as an 8-digit binary number. Convert the 8-digit binary number into a 2-digit hexadecimal number. There is 16 columns, and therefore a 32-digit hexadecimal number can be used to indicate the on/off state of the LEDs. The following figure shows the LEDs on the LED matrix.


image


Example program 1

from halocode import *
led_matrix.show(image = "hello", index = 1) #Enables the LED matrix to display the image "hello"


Example program 2

from halocode import *
led_matrix.show(image = "00003c7e7e3c000000003c7e7e3c0000", index = 1) 
#Enables the LED matrix to display the image "hello"


led_matrix.print(message, index = 1)

Displays the specified characters on the LED matrix in scrolling mode.

Parameters:


led_matrix.print_until_done(message, index = 1)

Displays the specified characters on the LED matrix until the scrolling ends.

Parameters:


led_matrix.print_at(message, x, y, index = 1)

Displays the specified characters with the specified start point (x,y) on the LED matrix.

Parameters:


led_matrix.on(x, y, index = 1)

Lights up the LED in the specified position (x,y) on the LED matrix.

Parameters:


led_matrix.off(x, y, index = 1)

Turns off the LED in the specified position (x,y) on the LED matrix.

Parameters:


led_matrix.toggle(x, y, index = 1)

Changes the state (on/off) of the LED in the specified position (x,y) on the LED matrix.

Parameters:


led_matrix.clear(index = 1)

Turns off all the LEDs on the LED matrix.


RGB LED

rgb_led.on(r, g, b, index = 1)

Sets the color of the RGB LED.

Parameters:

red r
orange o
yellow y
green g
cyan c
blue b
purple p
white w
black k


rgb_led.off(index = 1)

Turns off the RGB LED.


rgb_led.set_red(val, index = 1)

Changes the R value of the RGB LED.

Parameters:


rgb_led.set_green(val, index = 1)

Changes the G value of the RGB LED.

Parameters:


rgb_led.set_blue(val, index = 1)

Changes the B value of the RGB LED.

Parameters:

rgb_led.add_red(val, index = 1)

Increases the R value of the RGB LED.

Parameters:


rgb_led.add_green(val, index = 1)

Increases the G value of the RGB LED.

Parameters:


rgb_led.add_blue(val, index = 1)

Increases the B value of the RGB LED.

Parameters:


rgb_led.get_red(val, index = 1)

Obtains the R value of the RGB LED.

Returns a numeric value ranging from 0 to 255.


rgb_led.get_green(index = 1)

Obtains the G value of the RGB LED.

Returns a numeric value ranging from 0 to 255.


rgb_led.get_blue(index = 1)

Obtains the B value of the RGB LED.

Returns a numeric value ranging from 0 to 255.


LED Driver

led_driver.on(r, g, b, id = "all", index = 1)

Sets the color of the specified LED or all LEDs.

Parameters:

red r
orange o
yellow y
green g
cyan c
blue b
purple p
white w
black k


led_driver.show(color, index = 1)

Sets color(s) for multiple LEDs.

Parameters:


led_driver.off(led_id = "all", index = 1)

Turns off the specified LED or all LEDs.

Parameters:


led_driver.set_red(val, led_id = "all", index = 1)

Changes the R value of the specified LED.

Parameters:


led_driver.set_green(val, led_id = "all", index = 1)

Changes the G value of the specified LED.

Parameters:


led_driver.set_blue(val, led_id = "all", index = 1)

Changes the B value of the specified LED.

Parameters:


led_driver.add_red(val, led_id = "all", index = 1)

Increases the R value of the specified LED.

Parameters:


led_driver.add_green(val, led_id = "all", index = 1)

Increases the G value of the specified LED.

Parameters:


led_driver.add_blue(val, led_id = "all", index = 1)

Increases the B value of the specified LED.

Parameters:


led_driver.set_mode(mode = "steady", index = 50)

Sets the display mode of the LED driver.

Parameters:

Play

Speaker

speaker.mute(index = 1)

Stops the playing of the speaker.


speaker.play_tone(freq, index = 1)

Sets the frequency of the speaker.

Parameters:


do / Cre / Dmi / Efa / Fsol / Gla / Asi / B
265 Hz73 Hz82 Hz87 Hz98 Hz110 Hz123 Hz
3131 Hz147 Hz165 Hz175 Hz196 Hz220 Hz247 Hz
4 (Standard Alto)262 Hz294 Hz330 Hz349 Hz392 Hz440 Hz494 Hz
5523 Hz587 Hz659 Hz698 Hz784 Hz880 Hz988 Hz
61047 Hz1175 Hz1319 Hz1397 Hz1568 Hz1760 Hz1976 Hz
72093 Hz2349 Hz2637 Hz2794 Hz3136 Hz3520 Hz3951 Hz
84186 Hz4699 Hz


For example, the standard alto pitch (the first international pitch) is A4 = 440Hz.


speaker.play_music(music, index = 1)

Plays the specified preset or user-defined audio file by the speaker.

Parameters:


speaker.play_music_until_done(music, index = 1)

Plays the specified preset or user-defined audio file by the speaker until the playing is complete.

Parameters:


speaker.set_vol(val, index = 1)

Sets the volume of the speaker.

Parameters:


speaker.add_vol(val, index = 1)

Changes the volume of the speaker (not applicable to some sounds with special frequency).

Parameters:


speaker.get_vol(index = 1)

Obtains the volume of the speaker.

Returns a numeric value ranging from 0 to 100. The value 100 indicates the maximum volume of the speaker.


speaker.is_play(index = 1)

Determines whether the speaker is playing music.

Returns a Boolean value:

True: playing music

False: not playing music

Motion

Motor Driver

motor_driver.set(power, index = 1)

Sets the output power of the motor driver.

Parameters:


motor_driver.add(power, index = 1)

Increases the output power of the motor driver.

Parameters:


motor_driver.get(index = 1)

Obtains the output power of the motor driver.

Returns a numeric value ranging from –100 to +100.


motor_driver.get_load(index = 1)

Obtains the load value of the motor driver. The load value varies according to the operation of the connected motor. When the motor operates with a heavy load or is stalled (heavy load may also be caused by short circuit), a large load value is obtained.

Returns a numeric value ranging from 0 to 1024.


motor_driver.stop(index = 1)

Stops the power output of the motor driver.


Servo Driver

servo_driver.set(angle, index = 1)

Sets the angle the servo connected to the servo driver is located.

Parameters:


servo_driver.add(angle, index = 1)

Sets the angle the connected servo rotates from the current position.

Parameters:


servo_driver.get(index = 1)

Obtains the angle the servo connected to the servo driver is located.

Returns a numeric value ranging from 0 to 180, in degrees (°).


servo_driver.get_load(index = 1)

Obtains the load value of the servo driver. The load value varies according to the operation of the connected servo. When the servo operates with a heavy load or is stalled (heavy load may also be caused by short circuit), a large load value is obtained.

Returns a numeric value ranging from 0 to 1024.


servo_driver.release(index = 1)

Releases the servo connected to the servo driver. After the servo is released, you can manually rotate it and the servo_driver.get(index) function can no longer obtains the correct angle of the servo.


Smart Servo Motor (12 Kg)

smart_servo.turn(angle, speed, index = 1)

Rotates the smart servo by the specified angle. This function blocks the current thread until the rotating is completed or suspended by another function.

Parameters:


smart_servo.turn_to(angle, speed, index = 1 )

Rotates the smart servo to the specified angle. This function blocks the current thread until the rotating is completed or suspended by another function.

Parameters:


smart_servo.run(power, index = 1)

Sets the speed at which the smart servo rotates.

Parameters:


smart_servo.stop(index = "all")

Stops the motion of the smart servo.

Parameters:


smart_servo.get_angle(index = 1)

Obtains the angle the smart servo is located.

Returns a numeric value, indicating the angle the smart servo rotates from the initial position.


smart_servo.get_speed(index = 1)

Obtains the rotating speed of the smart servo, either the automatic rotating or the rotating drived by external force.

Returns a numeric value. indicating the rotating speed, in degrees per second (°/s).


smart_servo.release_angle(index = "all")

Releases the smart servo. After the smart servo is released, it is no longer locked at the angle and you can rotate it manually. If you do not rotate it, it remains at the angle when it is released until any one of the following functions is executed:

smart_servo.turn(angle)

smart_servo.turn_to(angle)

smart_servo.drive(power, t = "forever")

smart_servo.lock_angle()


smart_servo.lock_angle(index = "all")

Locks the smart servo at the current angle. After being locked, a smart servo cannot be rotated by external force.


smart_servo.reset(index = "all")

Resets the smart servo. After being reset, the smart servo takes the current position as the zero point. The number of times a smart servo can be reset is limited, and therefore this function blocks the current thread for three seconds to prevent it from being executed again.

Other modules

IR Remote

ir.send(message, index = 1)

Sends an IR message.

Parameters:


ir.receive(index = 1)

Obtains the received IR message.

Returns a character string.

ir.record(record_id, index = 1)

Records an IR message. This API function blocks the current thread for three seconds to complete the recording of the IR signal.

Parameters:


ir.send_record(record_id, index = 1)

Sends the recorded IR message.

Parameters:


ir.is_receive(message, index = 1)

Determines whether the IR remote module receives the specified IR signal.

Parameters:


VariableDefinition
IR_REMOTE.up
IR_REMOTE.down
IR_REMOTE.left
IR_REMOTE.right
IR_REMOTE.setSetting
IR_REMOTE.zero0
IR_REMOTE.one1
IR_REMOTE.two2
IR_REMOTE.three3
IR_REMOTE.four4
IR_REMOTE.five5
IR_REMOTE.six6
IR_REMOTE.seven7
IR_REMOTE.eight8
IR_REMOTE.nine9
IR_REMOTE.AA
IR_REMOTE.BB
IR_REMOTE.CC
IR_REMOTE.DD
IR_REMOTE.EE
IR_REMOTE.FF