Input modules

Interaction Modules

Button

资源 4@2x-8.png  button.is_press(index = 1)

Detects whether the button is pressed.

Returns a boolean value:

True: button pressed

False: button not pressed

资源 4@2x-8.png button.get_count(index = 1)

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

Returns a numeric value.

 

资源 4@2x-8.png button.reset_count(index = 1)

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

 

Angle Sensor

资源 4@2x-8.png 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 counterclockwise.

 

资源 4@2x-8.png angle_sensor.reset(index = 1)

Resets the angle the angle sensor rotates.

 

资源 4@2x-8.png 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 counterclockwise.

 

资源 4@2x-8.png 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

 

资源 4@2x-8.png angle_sensor.is_anticlockwise(index = 1)

Detects whether the angle sensor is rotating counterclockwise.

Returns a boolean value:

True: rotating counterclockwise

False: not rotating counterclockwise

 

Slider

资源 4@2x-8.png 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

资源 4@2x-8.png 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.

 

资源 4@2x-8.png joystick.get_y(index = 1)

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

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

 

资源 4@2x-8.png joystick.is_up(index = 1)

Determines whether the joystick pivots upwards.

Returns a boolean value:

True: pivoting upward

False: not pivoting upward

 

资源 4@2x-8.png joystick.is_down(index = 1)

Determines whether the joystick pivots downward.

Returns a boolean value:

True: pivoting downward

False: not pivoting downward

 

资源 4@2x-8.png 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

 

资源 4@2x-8.png 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

资源 4@2x-8.png 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:

  • ch: character string or numeric value. The default value is any. To set ch to a character string, it must be set to any, which indicates that the touching of any touch sensor can be detected.
    To set ch to a numeric value, it can be set to a number ranging from 1 to 8, which indicates the serial number of the corresponding touch sensor.

Returns a boolean value:

True: touched

False: not touched

 

资源 4@2x-8.png multi_touch.reset(level = "middle", index = 1)

Sets the threshold for Multi Touch.

Parameters:

  • level: character string. The values are described as follows:
    low: low sensitivity
    middle: moderate sensitivity
    high: high sensitivity

 

Sensors

Science sensor

The science sensor is a multi-in-one sensor developed independently by Makeblock. Integrating the gas, heart rate, magnetic field, flame, air pressure, temperature & humidity, PIR, touch, and soil moisture sensing components, the science sensor can be used in various data collecting, science exploring, and Internet of Things (IoT) projects.

For more information about the science sensor, see Science Sensor.

The following describes the APIs provided for the science sensor. Like the other mBuild modules, each API for the science sensor includes the parameter index, which is a common parameter. For the definition and function of this parameter, see "Common parameter index."

 

PIR sensor

资源 4@2x-8.png science.pir_is_active(index=1)

Determines whether the PIR sensor on the science sensor detects the motion of a human being or animal.

A boolean value is returned.

 

Fire sensor

资源 4@2x-8.png science.flame_is_active(index=1)

Determines whether the fire sensor on the science sensor detects a flame.

A boolean value is returned.

 

资源 4@2x-8.png cyberpi.science.flame_get(index=1)

Obtains the output value of the fire sensor.

An integer is returned.

 

Soil moisture sensor

资源 4@2x-8.png science.soil_get(index=1)

Obtains the output value of the soil moisture sensor, that is, the soil moisture value.

An integer is returned.

 

资源 4@2x-8.png science.soil_get_resistance(index=1)

Obtains the resistance (kΩ) between the two probes of the soil moisture sensor.

An integer is returned.

 

资源 4@2x-8.png science.soil_get_adc_value(index=1)

Determines whether electricity is conducted between the two probes of the soil moisture sensor.

A boolean value is returned.

 

MQ2 gas sensor

资源 4@2x-8.png science.mq2_is_active(index=1)

Determines whether the MQ2 gas sensor on the science sensor detects a flammable gas.

A boolean value is returned.

 

资源 4@2x-8.png science.mq2_get(index=1)

Obtains the output value of the MQ2 gas sensor, that is, the concentration of the flammable gas.

An integer is returned.

 

资源 4@2x-8.png science.mq2_on(threshold, index=1)

Turns the MQ2 gas sensor on and sets its sensitivity.

  • threshold: float, sensitivity of the sensor, ranging from 0.1 to 1.0, where a greater value indicates a higher sensitivity

 

资源 4@2x-8.png science.mq2_off(index=1)

Turns the MQ2 gas sensor off.

 

Touch sensor

资源 4@2x-8.png science.touch_get_resistance(index=1)

Obtains the resistance (kΩ) detected at the touch point of the touch sensor on the science sensor.

An integer is returned.

 

资源 4@2x-8.png science.touch_get_adc_value(index=1)

Determines whether the touch point of the touch sensor is touched.

A boolean value is returned.

 

Humiture sensor

资源 4@2x-8.png science.humiture_get_temp(index=1)

Obtains the temperature (in degrees centigrade) detected by the humiture sensor.

A float value is returned.

 

资源 4@2x-8.png science.humiture_get_humidity(index=1)

Obtains the humidity (in percentage) detected by the humiture sensor.

An integer is returned.

 

Magnetic field sensor

资源 4@2x-8.png science.compass_get(axis,index = 1)

Obtains the amount (Φ/G) of the magnetic flux detected at the specified axis (x, y, or z).

The axes of the science sensor are defined as follows:

ee6b761af63043428897831c01337520.png

  • axis: str, axis at which the magnetic flux is to be detected

setting range: x, y, z

An integer is returned.

 

资源 4@2x-8.png science.compass_get_angle(index = 1)

Obtains the the compass direction (angle) detected by the magnetic field sensor.

An integer is returned.

 

资源 4@2x-8.png science.compass_reset(switch,index = 1)

Enables or disables the function for calibrating the magnetic field sensor.

  • switch: int, setting range: 0 and 1, where 0 indicates disabling and 1 indicates enabling

 

资源 4@2x-8.png science.compass_is_active(index = 1)

Determines whether the magnetic field sensor detects a magnet.

A boolean value is returned.

 

Air pressure sensor

资源 4@2x-8.png science.atmos_get(index=1)

Obtains the air pressure detected by the air pressure sensor.

An integer is returned.

 

资源 4@2x-8.png science.atmos_get_altitude(index = 1)

Obtains the altitude estimated by the air pressure sensor.

An integer is returned.

 

Quad RGB Sensor

image.png

资源 4@2x-8.png quad_rgb_sensor.get_line_sta(index = 1)

Obtains the state of the background.

Returns an integer ranging 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

1596105046894-ff21ac5f-bb06-4b46-a5ab-78aa929bb59b.png

1

0001

2.png

2

0010

3.png

3

0011

4.png

4

0100

5.png

5

0101

6.png

6

0110

7.png

7

0111

8.png

8

1000

8.png

9

1001

9.png

10

1010

10.png

11

1011

11.png

12

1100

12.png

13

1101

13.png

14

1110

14.png

15

1111

15.png

 

资源 4@2x-8.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 ranging from –100 to +100. The deviation of –100 indicates that Quad RGB Sensor is on the left of the line to be followed.

 

资源 4@2x-8.png quad_rgb_sensor.is_line(ch, index = 1)

Determines whether a line is detected by the specified sensor.

Parameter:

  • ch: int or str, indicates the specified sensor.

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

Returns a boolean value:

True: detected

False: not detected

 

资源 4@2x-8.png quad_rgb_sensor.is_background(ch, index = 1)

Determines whether a background is detected by the specified sensor.

Parameter:

  • ch: int or str, indicates the specified sensor.

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

Returns a boolean value:

True: detected

False: not detected

 

资源 4@2x-8.png quad_rgb_sensor.is_color(color = "white", ch, index = 1)

Determines whether the specified sensor detects the specified color.

Parameters:

  • color: string, indicates the specified color. The following describes the colors and their abbreviations:
red r

yellow y

green g

cyan c

blue b

purple p

white w

black k

 

  • ch: int or str, indicates the specified sensor.

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

Returns a boolean value:

True: detected

False: not detected

 

资源 4@2x-8.png quad_rgb_sensor.get_red(ch, index = 1)

Obtains the R value of the color detected by the sensor

Parameter:

  • ch: int or str, indicates the specified sensor.

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

Returns a value ranging from 0 to 255.

 

资源 4@2x-8.png quad_rgb_sensor.get_green(ch, index = 1)

Obtains the G value of the color detected by the sensor

Parameter:

  • ch: int or str, indicates the specified sensor.

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

Returns a value ranging from 0 to 255.

 

资源 4@2x-8.png quad_rgb_sensor.get_blue(ch, index = 1)

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

Parameter:

  • ch: int or str, indicates the specified sensor.

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

Returns a value that ranging from 0 to 255.

 

资源 4@2x-8.png quad_rgb_sensor.get_gray(ch, index = 1)

Obtains the gray 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:

  • ch: int or str, indicates the specified sensor.

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

Returns a value ranging from 0 to 100.

 

资源 4@2x-8.png quad_rgb_sensor.get_color(ch, index = 1)

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

Parameter:

  • ch: int or str, indicates the specified sensor.

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

Returns a hex value ranging from 0x000000 to 0xffffff.

 

资源 4@2x-8.png quad_rgb_sensor.get_color_sta(ch, index = 1)

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

Parameter:

  • ch: int or str, indicates the specified sensor.

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"

 

资源 4@2x-8.png 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:

  • ch: int or str, indicates the specified sensor.

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

Returns a value ranging from 0 to 100.

 

资源 4@2x-8.png quad_rgb_sensor.set_led(color = "white", index = 1)

Sets the color of all fill lights.

Parameter:

  • color: string or hex, indicates the color of the fill lights.

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.

 

资源 4@2x-8.png 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

资源 4@2x-8.png ultrasonic2.get(index = 1)

Obtains the distance between an obstacle and the ultrasonic sensor 2.

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

 

资源 4@2x-8.png ultrasonic2.led_show(bri, index =1)

Sets the brightness of all the LEDs.

Parameter:

  • bri: int_list

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.

image (1).png

 

资源 4@2x-8.png ultrasonic2.set_bri(led_bri, id, index =1)

Sets the brightness of the specified LED.

Parameters:

  • led_bri float: brightness of the specified LED, ranging from 0 to 100
  • id: int or str

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

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

 

资源 4@2x-8.png ultrasonic2.add_bri(led_bri, id, index =1)

Increases the brightness of the specified LED.

Parameters:

  • led_bri float: value by which the brightness is to be increased, ranging from 0 to 100.
  • id: int or str

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

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

 

资源 4@2x-8.png ultrasonic2.get_bri(id, index =1)

Obtains the brightness of the specified LED.
Parameter:

  • id: int or str

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

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

资源 4@2x-8.png ultrasonic2.play(emotion, index =1) [to be implemented]

Makes the ultrasonic sensor 2 express the specified emotion through its blue LEDs.

This API blocks the thread till the emotion is completely expressed.

Parameter:

emotion: str

 

The following table describes the available values and their corresponding emotions.

 

Value Emotion
"sleepy" Standby
"happy" Happy
"dizzy" Dizzy
"wink" Raise eyebrows
"thinking" Thinking

 

Light Sensor

资源 4@2x-8.png 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

资源 4@2x-8.png dual_rgb_sensor.is_color(color = "white", ch, index = 1)

Determines whether the color sensor detects the specified color.

Parameters:

  • color: character string. It indicates the color to be detected. The following shows the color names and their abbreviations:
red r
yellow y
green g
cyan c
blue b
purple p
white w
black k
  • ch: numeric value, ranging from 1 to 2, where 1 indicates RGB1, and 2 indicates RGB2.

Returns a boolean value:

True: detected

False: not detected

 

资源 4@2x-8.png dual_rgb_sensor.get_red(ch = 1, index = 1)

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

Parameters:

  • ch: numeric value ranging from 1 to 2, where 1 indicates RGB1 and 2 indicates RGB2. The default value is 1.

Returns a numeric value ranging from 0 to 255.

 

资源 4@2x-8.png dual_rgb_sensor.get_green(ch = 1, index = 1)

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

Parameters:

  • ch: numeric value ranging from 1 to 2, where 1 indicates RGB1 and 2 indicates RGB2. The default value is 1. gitbb Returns a numeric value ranging from 0 to 255.

 

资源 4@2x-8.png dual_rgb_sensor.get_blue(ch = 1, index = 1)

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

Parameters:

  • ch: numeric value ranging from 1 to 2, where 1 indicates RGB1 and 2 indicates RGB2. The default value is 1.

Returns a numeric value ranging from 0 to 255.

 

资源 4@2x-8.png 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:

  • ch: numeric value ranging from 1 to 2, where 1 indicates RGB1 and 2 indicates RGB2. The default value is 1.

Returns a numeric value ranging from 0 to 100.

 

资源 4@2x-8.png 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:

  • ch: numeric value ranging from 1 to 2, where 1 indicates RGB1 and 2 indicates RGB2. The default value is 1.

Returns a numeric value ranging from 0 to 100.

 

资源 4@2x-8.png dual_rgb_sensor.set_led(color = "white", index = 1)

Sets the color of the fill light.

Parameters:

  • color: character string. It indicates the color in which the fill light is lit up. The following shows the color names and their abbreviations:
red r
yellow y
green g
cyan c
blue b
purple p
white w
black k
  • ch: numeric value ranging from 1 to 2, where 1 indicates RGB1 and 2 indicates RGB2.

 

资源 4@2x-8.png 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 you use the API for detecting colors.

 

Sound Sensor

资源 4@2x-8.png sound_sensor.get(index = 1)

Obtains the output value of the sound sensor.

Returns a numeric value ranging from 0 to 100.

 

PIR Sensor

资源 4@2x-8.png pir.is_detect(index = 1)

Determines whether the PIR sensor detects the motion of a human being or animal. 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 or aniaml motion in the subsequent three seconds.

Returns a boolean value:

True: motion detected

False: no motion detected

 

资源 4@2x-8.png pir.get_count(index = 1)

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

Returns a positive integer.

 

资源 4@2x-8.png pir.reset_count(index = 1)

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

 

Ultrasonic Sensor

资源 4@2x-8.png 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

资源 4@2x-8.png 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

资源 4@2x-8.png motion_sensor.is_shake(index = 1)

Detects whether the motion sensor is shaken.

Returns a boolean value:

True: shaken

False: not shaken

 

资源 4@2x-8.png 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.

 

资源 4@2x-8.png motion_sensor.get_accel(axis, index = 1)

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

Parameters:

  • axis: character string, which can be x, y, or z, indicating an axis defined for the motion sensor.

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

 

资源 4@2x-8.png 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

 

资源 4@2x-8.png 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

 

资源 4@2x-8.png 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

 

资源 4@2x-8.png 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

 

资源 4@2x-8.png motion_sensor.is_faceup(index = 1)

Detects whether the motion sensor is placed face up.

True: placed face up

False: not placed face up

资源 4@2x-8.png motion_sensor.is_facedown(index = 1)

Detects whether the motion sensor is placed face down.

True: placed face down

False: not placed face down

资源 4@2x-8.png 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 (°).

 

资源 4@2x-8.png 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 (°).

 

资源 4@2x-8.png 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.

 

资源 4@2x-8.png motion_sensor.get_gyro(axis, index = 1)

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

Parameters:

  • axis: character string, which can be x, y, or z, indicating an axis defined for the motion sensor.

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

 

资源 4@2x-8.png 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 counterclockwise.

Parameters:

  • axis: character string, which can be x, y, or z, indicating an axis defined for the motion sensor.

Returns a numeric value in degrees (°).

 

资源 4@2x-8.png 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:

  • axis: character string, which can be x, y, z, or all. x, y, and z are the axes defined for the motion sensor. The default value is all, indicating all the three axes.

 

Soil Moisture Sensor

资源 4@2x-8.png 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

资源 4@2x-8.png 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

资源 4@2x-8.png humiture.get_humidity(index = 1)

Obtains the humidity detected by the humiture sensor.

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

 

资源 4@2x-8.png humiture.get_temp(index = 1)

Obtains the temperature detected by the humiture sensor.

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

 

MQ2 Gas Sensor

资源 4@2x-8.png mq2.is_detect(level = “high”, index = 1)

Determines whether the concentration of the detected flammable gas exceeds the threshold.

Parameters:

  • level: character string. The values are described as follows:

high: high sensitivity, with which the sensor is triggered more easily

low: low sensitivity, with which the sensor isn't triggered easily

资源 4@2x-8.png 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 concentration of flammable gas.

 

Flame Sensor

资源 4@2x-8.png flame_sensor.is_detect(index = 1)

Determines whether a flame is detected.

Returns a boolean value:

True: detected

False: not detected

 

资源 4@2x-8.png flame_sensor.get(index = 1)

Obtains the output value of the flame sensor.

Returns a numeric value ranging from 0 to 100.

 

Magnetic Sensor

资源 4@2x-8.png 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

 

资源 4@2x-8.png 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.

 

资源 4@2x-8.png magnetic_sensor.reset_count(index = 1)

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

 

Smart Camera

资源 4@2x-8.png smart_camera.set_mode(mode = "color", index = 1)

Sets the detection mode of the smart camera.

Parameters:

  • mode: character string.
    color: color block detection mode, in which the smart camera can detect and trace color blocks
    line: line tracking mode, in which the smart camera can track lines and barcodes.

 

资源 4@2x-8.png smart_camera.learn(sign = 1, t = "until_button", index = 1)

Sets the number of the color block to be learned.

Parameters:

  • sign: numeric value ranging from 1 to 7, indicating the number of a color block.
  • t: numeric value or character string. The default value is until_button.
    To set t to a character string, it must be set to until_button, which indicates that the learning ends when the on-board button is pressed.
    When t is set to a numeric value, it indicates the waiting time before the color block is learned and recorded. The thread is blocked until the learning and recording are complete.

 

资源 4@2x-8.png smart_camera.detect_sign(sign, index = 1)

Determines whether the specified color block is detected.

Parameters:

  • sign: numeric value ranging from 1 to 7, indicating the serial number of a color block.

Returns a boolean value:

True: detected

False: not detected

 

资源 4@2x-8.png 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:

  • sign: numeric value ranging from 1 to 7, indicating the serial number of a color block.
  • location: character string. The values are described as follows:
    up: upper area of the captured image
    down: lower area of the captured image
    left: left side of the captured image
    right: right side of the captured image
    middle: center of the captured image
    The following figure shows the areas of a captured image.


A7E889A8E597AFE5AB8C%BA.png

Returns a boolean value:

True: detected

False: not detected

 

资源 4@2x-8.png smart_camera.get_sign_x(sign, index = 1)

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

Parameters:

  • sign: numeric value ranging from 1 to 7, indicating the serial number of a color block.

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

 

资源 4@2x-8.png smart_camera.get_sign_y(sign, index = 1)

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

Parameters:

  • sign: numeric value ranging from 1 to 7, indicating the serial number of a color block.

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

 

资源 4@2x-8.png smart_camera.get_sign_wide(sign, index = 1)

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

Parameters:

  • sign: numeric value ranging from 1 to 7, indicating the serial number of a color block.

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

 

资源 4@2x-8.png smart_camera.get_sign_hight(sign, index = 1)

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

Parameters:

  • sign: numeric value ranging from 1 to 7, indicating the serial number of a color block.

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

 

资源 4@2x-8.png smart_camera.open_light(index = 1)

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

 

资源 4@2x-8.png smart_camera.close_light(index = 1)

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

 

资源 4@2x-8.png smart_camera.reset(index = 1)

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

 

资源 4@2x-8.png smart_camera.detect_label(label, index = 1)

Determines whether the specified barcode is detected.

Parameters:

  • label: numeric value ranging from 1 to 15, indicating the serial number of a barcode.

Returns a boolean value:

True: detected

False: not detected

 

资源 4@2x-8.png smart_camera.get_label_x(label, index = 1)

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

Parameters:

  • label: numeric value ranging from 1 to 15, indicating the serial number of a barcode.

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

 

资源 4@2x-8.png smart_camera.get_label_y(sign, index = 1)

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

Parameters:

  • label: numeric value ranging from 1 to 15, indicating the serial number of a barcode.

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

 

资源 4@2x-8.png smart_camera.detect_cross(index = 1)

Determines whether an intersection is detected in the captured image.

 

资源 4@2x-8.png 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.

 

资源 4@2x-8.png 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.

 

资源 4@2x-8.png smart_camera.get_cross_road(index = 1)

Obtains the number of detected crossroads.

Returns a numeric value.

 

资源 4@2x-8.png 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:

  • sn: numeric value, indicating the space of a crossroad among the ones detected in the captured image. The number 1 indicates the first crossroad, 2 indicates the second one, and so on.

 

资源 4@2x-8.png smart_camera.set_line(mode = "black, index = 1)

Sets the color preference for the line tracking mode.

Parameters:

  • mode: character string. The values are described as follows:
    black: detecting dark lines in light backgrounds
    white: detecting light lines in dark backgrounds

 

资源 4@2x-8.png 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.

 

资源 4@2x-8.png 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.

 

资源 4@2x-8.png 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.

 

资源 4@2x-8.png 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.

 

资源 4@2x-8.png smart_camera.set_vector_angle(angle, index = 1)

Sets the angle preference for the vector.

Parameters:

  • angle: numeric value, indicating the angle preference for the vector. After the setting, the smart camera takes the crossroad whose angle is closest to the set value as the next vector.

 

资源 4@2x-8.png smart_camera.get_vector_angle(index = 1)

Obtains the set angle preference.

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

 

资源 4@2x-8.png smart_camera.set_kp(kp, index = 1)

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

Parameters:

  • kp: numeric value.

 

资源 4@2x-8.png 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:

  • sign: numeric value ranging from 1 to 7, indicating the serial number of a color block.
  • axis: character string. The values are described as follows:
    x: specifies the x-axis
    y: specifies the y-axis
  • axis_val: numeric value. If axis is set to x, the setting range is 0 to 319; and if axis is set to y, the setting range is 0 to 239.

Returns a numeric value ranging from 0 to 100.

 

资源 4@2x-8.png 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:

  • label: numeric value ranging from 1 to 15, indicating the serial number of a barcode.
  • axis: character string. The values are described as follows:
    x: specifies the x-axis
    y: specifies the y-axis
  • axis_val: numeric value. If axis is set to x, the setting range is 0 to 319; and if axis is set to y, the setting range is 0 to 239.

Returns a numeric value ranging from 0 to 100.

 

资源 4@2x-8.png 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.

 

资源 4@2x-8.png 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:

  • sign: numeric value ranging from 1 to 7, indicating the serial number of a color block.
  • axis: character string. The values are described as follows:
    x: specifies the x-axis
    y: specifies the y-axis
  • axis_val: numeric value. If axis is set to x, the setting range is 0 to 319; and if axis is set to y, the setting range is 0 to 239.

Returns a boolean value:

True: near the specified point

False: not near the specified point

 

资源 4@2x-8.png 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:

  • label: numeric value ranging from 1 to 15, indicating the serial number of a barcode.
  • axis: character string. The values are described as follows:
    x: specifies the x-axis
    y: specifies the y-axis
  • axis_val: numeric value. If axis is set to x, the setting range is 0 to 319; and if axis is set to y, the setting range is 0 to 239.

Returns a boolean value:

True: near the specified point

False: not near the specified point

Was this article helpful?
1 out of 1 found this helpful

Comments

0 comments

Please sign in to leave a comment.