mCookie

All extension methods and properties in the mCookie library depend on the mcookie extension package. Please import mcookie before use.

import mcookie

The 'mCookie Extension' firmware is available for all but the OLED module. In the text, the parameters that support the float type or the valid string float type are directly converted into int type in actual operation. For example, 2.3 is equivalent to 2, '2.6' is equivalent to 2

action

1、Motor speed

Motor00

mcookie.motorContro(ports, speed)
"""
    ports : Motor port (including two ports, 1A1B and 2A2B) default 1A1B, parameters 0 and 1
    speed : Motor speed (default 30r/min)
    Function : Control the motor to run at the specified speed
    Parameter type: ports and speed support int, float and pure numeric strings)
    Applicable modules : Sensor expansion board
"""

ports is 0 for 1A1B, 1 for 2A2B; ports are automatically rounded to int when float type or string float

2、Motor stops

Motor00

mcookie.motorBrake(ports)
"""
    ports : Motor port (includes two ports, 1A1B and 2A2B) with parameters 0 and 1
    Function : Stop the motor of the specified port 
    Parameter type: ports support int, float, and pure numeric strings
    Applicable modules : Sensor expansion board
"""

ports is 0 for 1A1B, 1 for 2A2B; ports are automatically rounded to int when float type or string float

3、Motor+ speed

Motor00

mcookie.motorplusControl(ports, speed)
"""
    ports : Motor port (includes two ports, 1A1B and 2A2B) with parameters 0 and 2
    speed : Motor speed (default 255r/min)
    Function : Control the motor to run at the specified speed
    Parameter type: ports and speed support int, float, and pure numeric strings
    Applicable modules : Sensor expansion board
"""

ports for 0 for 1A1B, 2 for 2A2B; ports for float type or string float will be automatically rounded to int

4、Motor+ stop

Motor00

mcookie.motorBrake(ports)
"""
    ports : Motor port (includes two ports, 1A1B and 2A2B) with parameters 0 and 2
    Function : Stop the motor of the specified port
    Parameter type: ports support int, float, and pure numeric strings
    Applicable modules : Sensor expansion board
"""

ports for 0 for 1A1B, 2 for 2A2B; ports for float type or string float will be automatically rounded to int

The left is the Motor module and the right is the Motor+ Module.

Motor00

5、Car control(Motor)

Motor00

mcookie.carControl(port1, port2)
"""
    port1 : Motor port 1A1B, the default parameter is -150 for counterclockwise speed 150r/min
    port2 : Motor port 2A2B, the default parameter is 150 for clockwise speed 150r/min 
    Function : Control the motor of the two ports to rotate in the opposite direction
    Parameter type : port1 and port2 support int, float, and pure data strings
    Applicable modules : Motor module
"""

port1 and port2 are automatically rounded to int when they are float type or string float

6、Car control

Motor00

mcookie.carPlusControl(150, 150)

"""
    port1 : Motor port 1A1B, the default parameter is 150 for counterclockwise speed 150r/min
    port2 : Motor port 2A2B, the default parameter is 150 for clockwise speed 150r/min
    Function : Control the motor of the two ports to rotate in the opposite direction
    Parameter type : port1 and port2 support int, float, and pure numeric strings
    Applicable modules : MotorPlus module
"""

There is a misunderstanding between the Motor module and the Motor+ module parameters in the car control. The default ‘-’ sign represents the reverse in the Motor module statement. The Motor+ module statement does not add the ‘-’ number to the 2A2B port.When the motor speed is low, the motor can't start normally. At this time, the speed must be increased. When port1 and port2 are float type or string float, they will be automatically rounded to int type.

7、Steering wheel rotation angle

Pin

arduino.servoWrite(port, angle)
"""
    port : Steering pin port, default is 2, parameter is 2
    angle : Steering wheel rotation angle
    Function : Rotate the servo under the specified pin to the desired angle
    Parameter types : port, angle for int, float, and pure numeric strings
    Applicable modules : Sensor expansion board
"""

8、Control servo speed

Motor00

mcookie.servoControl(port, value1, value2, delay)
"""
    port : Steering pin port, default is 2/3 port, parameter is 2
    value1 : The starting value of the steering gear is 30 by default.
    value2 : The default rotation value of the servo is 120.
    delay :  Steering gear continuous rotation time defaults to 500ms
    Function : Control the steering gear from the rotation value1 to value2 within the specified time
    Parameter types: port, speed1, speed2 support int, float, and strings(numeric)
    Applicable modules : Sensor expansion board
"""

port is automatically rounded to int when it is a float type or a string float

Display

9、LED lights gradient

ColorLED00

mcookie.colorLEDControl(port, num, color1, color2, delay)
"""
    port : Lantern pin port, default is 2/3 port, parameter is 2 
    num : Lantern index value, the lantern can be used in series, starting from the first one connected to the expansion port, the index value is 0, 1, 2... The default value is 0, that is, the first lantern
    color1 : The starting color value of the lantern, the default is '#b20862' (color hex string)
    color2 : The end color of the lantern, the default is '#136e17' (color hex string)
    delay : Lantern transition time from the start color to the end color, the default is 500ms
    Function : Controls the lantern to change the gradient between the initial color and the end color within the specified time.
    Parameter types: port, num, delay support int, float, and pure numeric strings, color1, color2 are hexadecimal color value string types
    Applicable modules : Sensor expansion board
"""

10、LED lights monochrome

ColorLED00

mcookie.colorLEDColor(port, num, color)
"""
    port : Lantern pin port, default is 2/3 port, parameter is 2
    num : Lantern index value, the lantern can be used in series, starting from the first one connected to the expansion port, the index value is 0, 1, 2... The default value is 0, that is, the first lantern
    color : Lantern color value, default is '#62f1e5' (color hex string)
    Function : Controls the lantern to change the gradient between the initial color and the end color within the specified time.
    Parameter type: port, num support int, float, and pure numeric strings, color is hexadecimal color value string type
    Applicable modules : Sensor expansion board
"""

The monochrome LED lantern has only one control interface, so it can only receive one command; the full-color LED has a control interface (IN), and a transfer interface (OUT) so it can receive multiple commands and pass commands to the next one. Full color LED lights, when used, you can choose monochrome or full color LEDs as needed

11、Dot screen pattern

ColorLED00

mcookie.dotMatrixColor(address,color)
"""
    address : Address range, default is 64
    color : Hexadecimal color value string, the color values of all points are spliced into a string, the default value is all #000000
    Port : IIC
    Applicable modules : Sensor expansion board
    Parameter type : address supports int, float, and pure data strings, color is character
"""

12、Dot matrix screen coloring

ColorLED00

mcookie.dotMatrixPoint(64, 1, 1, '#6d26ea')
"""
    address : Address range, default is 64
    x : x coordinate value, default value is 1
    y : y coordinate value, default value is 1
    color : Hexadecimal color value string, default value is #6d26ea'
    Port : IIC
    Applicable modules : Sensor expansion board
    Parameter type : address, x, y support int, float and pure data type string, color is character type
"""

Dot matrix address description: 1、Address range: 1~64, over 64 is 64 2、Address representation method: The number of green dots displayed after the dot matrix is powered on indicates the dot matrix address 3、Address setting method: Within 3 seconds after the dot matrix is powered on, press the back button to enter the address configuration state, and the dot color changes to white. - Slow press of the button (2 times button interval greater than 0.5s) will increase the address - Press the button (2 times button interval is less than 0.5s) will reduce the address. After the dot matrix address is set, press and hold the setting button for 3 seconds to exit the address configuration state.

13、RGB color value

ColorLED00

combineRGB(R, G, B)
"""
    R : Three primary colors (red), default is 255
    G : Three primary colors (green), default is 0
    B : Three primary colors (blue), default is 0
    Function : Use R, G, B to combine the required color
    Parameter type: R, G, B support int, float, and pure data font strings
"""

14、OLED clear screen

Oled_00

mcookie.oledClear()
"""
    Function : Used to clear the current display content of the OLED display
    Applicable modules : OLED expansion module 
    Firmware selection : Suitable for burning mCookie firmware
    Applicable modules : Sensor expansion board
"""

Other instructions can be directly burned to the ‘mCookie extension’ firmware, but the OLED module needs to be burned to the ‘mCookie’ firmware for normal use, otherwise there will be a failure that the OLED cannot display.

15、OLED information

Oled_00

mcookie.oledMessage(x, y, msg)
"""
    x : x coordinate value, default value is 10
    y : y coordinate value, the default value is 10
    Msg : information to be displayed on the OLED display
    Function : Display specified information on the OLED display
    Firmware selection : Suitable for burning mCookie firmware
    Applicable modules : Sensor expansion board
"""

OLED displays do not support escape characters, special characters and Chinese characters in Python syntax,For example, the escape character: '\n', '\r', '\t'... special characters: ¥∆ ̊¬πœ∑†¥åß∂ƒ ̇∆ ̊©...Otherwise, garbled characters or mixed characters may be too long (special characters plus Chinese characters or individual special characters total length longer than 15 characters) may cause continuous flashing or occasional crashes. Occasionally, when the crash occurs, you must disconnect and reconnect to resume normal.

16、OLED line drawing - drawing rectangle

Oled_03

mcookie.oledDraw(type, x0, y0, x1, y1)
"""
    type : Drawing type, default is 0, including 0 (draw line), 1 (draw rectangle)
    x0 : Line or rectangle (the starting point of the rectangle is the point in the diagonal) Starting point x coordinate y
    y0 : Line or rectangle (the starting point of the rectangle is the point in the diagonal) starting point y coordinate
    x1 : Line or rectangle (the end point of the rectangle is the point in the diagonal) from the end point x coordinate
    y1 : Line or rectangle (the end point of the rectangle is the point in the diagonal) from the end point y coordinate
    Function : Draw straight lines, slashes, rectangles
    Applicable modules : Sensor expansion board
    Firmware selection : Suitable for burning mCookie firmware
"""

17、OLED circle

Oled_04

mcookie.oledCircle(x, y, r)
"""
    x : x coordinate value, default value is 10
    y : y coordinate value, the default value is 10
    r : radius of the circle
    Function : Draw a circle with the specified coordinate point as the center of the circle r
    Applicable modules : Sensor expansion board
    Firmware selection : Suitable for burning mCookie firmware
"""

18、Digital tube pin

Tube

mcookie.setNixietube(port, num1, num2, point)
"""
    port : Digital tube pin port, the default port is 2/3, the parameter is 2
    num1 : The digital tube index value allows the digital tube to be used in series. From the first connection to the expansion port, the index value is 0, 1, 2... The default value is 0, which is the first digital tube.
    num2 : To select the digital content to be displayed by the digital tube, mcookie.sendNixieTube(port, num1, num2, point) must be called when the digital tube is closed, and num1+=1 when it is closed.
    point : Decimal point, containing three states 0 (without), 1 (band), 3 (for off state)
    Function : Specify the digital tube and display the specified number
    Parameter type: port, num1, num2, point all support int, float, and numeric strings
    Applicable modules : Sensor expansion board
"""

Play

19、Buzzer tone

ColorLED00

mcookie.buzzerNote(port, beat, delay1)
time.sleep(delay2)
"""C
    port : Buzzer pin port, default is 2/3 port, parameter is 2
    Beat : Note beat includes (C4, D4, E4, F4, G4, A4, B4, C5, D5, E5, F5, G5, A5, B5, C6, D6, E6, F6, G6, A6, B6) Default C4 With a parameter of 262
    delay1 : Buzzer duration defaults to 250ms
    delay2 : Buzzer duration defaults to 250ms
    Applicable modules : Sensor expansion board
    Parameter types: port, beet, delay1, delay2 support int, float, and pure data strings
"""

The frequency value corresponding to the beat is:C4(262)、D4(294)、E4(330)、F4(349)、G4(392)、A4(440)、B4(494)、C5(523)、D5(587)、E5(659)、F5(698)、G5(784)、A5(880)、B5(988)、C6(1047)、D6(1175)、E6(1319)、F6(1397)、G6(1568)、A6(1760)、B6(1976); Delay1 is an invalid value and cannot be used as a normal delay. The delay operation needs to import import time -> time.sleep(delay2) delay2 is the delay time in ms.

20、Buzzer frequency

ColorLED00

mcookie.buzzerControl(port, frequency, delay1)
time.sleep(delay2)
"""
    port : Buzzer pin port, default is 2/3 port, parameter is 2
    frequency : Buzzer vibration frequency
    delay1 : Sounder duration defaults to 250ms
    delay2 : Sounder duration defaults to 250ms
    Applicable modules : Sensor expansion board
    Parameter types: port, beet, delay1, delay2 support int, float, and pure data strings
"""

Delay1 is an invalid value and cannot be used as a normal delay. The delay operation needs to import import time -> time.sleep(delay2) delay2 is the delay time in ms.

21、Buzzer playing music

ColorLED00

mcookie.buzzerSong(port, type)
"""
    port : Buzzer pin port, default is 2/3 port, parameter is 2
    type : Music type, default is 1
    Applicable modules : Sensor expansion board 
    Parameter type : port, type support int, float, and pure data string
"""

The main types of music are: 1 (A handkerchief ), 2 (two tigers), 3 (Doraemon), 4 (small apple)

22、Buzzer off

ColorLED00

mcookie.buzzerOff(port)
"""
    port : Buzzer pin port, default is 2/3 port, parameter is 2
    Function : Turn off music playback on the specified port
    Applicable modules : Sensor expansion board 
    Parameter type : port supports int, float, and pure data strings
"""

Perception

23、switch status

ColorLED00

mcookie.touchKey(port, status)
"""
    port : Listens to the switch status of the specified port. The default is 2/3 port. The parameter is 1.
    status : Switch status, mainly 1 (lifted), 0 (pressed), 2 (long press)
    Return value type : Return type is bool type, return True if the status is true or False
    Parameter type : port, status supports int, float, and pure data string
    Applicable modules : Sensor expansion board    
"""

24、Rocker button status

ColorLED00

mcookie.joystickKey(port, button, status)
"""
    port : Monitors the status of the mast button on the specified port. The default is A0, the parameter is 0, and the A0-A7 port is supported. The parameter is 0-7.
    button : The designated button of the mast defaults to 'up', the parameter is 1, mainly there are 'up' (1), 'down' (2), 'left' (3), 'right' (4), 'central' (0 ),
    status : Switch status, mainly 1 (lifted), 0 (pressed), 2 (long press)
    Return value type : Return type is bool type, return True if the status is true or False
    Parameter type : port, button, status, support for int, float, and pure data string
    Applicable modules : Sensor expansion board
"""

25、Infrared remote control state

IR00

mcookie.irKey(port, button, status)
"""
    port : Infrared remote control pin port, default is 2/3 port, parameter is 2
    button : Remote control status command, default is Power, parameter is 0x1FE48B7
    status : Switch status, mainly 1 (lifted), 0 (pressed), 2 (long press)
    Return value type : Return type is bool type, return True if the status is true or False
    Parameter type: port, status, support int, float, and pure data type string, button is standard hexadecimal
    Applicable modules : Sensor expansion board
"""

he command of the controller mainly includes: Power (0x1FE48B7), A (0x1FE807F), B (0x1FE40BF), C (0x1FEC03F), D (0x1FE20DF), E (0x1FE609F), OK (0x1FE10EF), upper (0x1FEA05F), lower ( 0x1FED827), left (0x1FEE01F), right (0x1FE906F), back (0x1FE50AF), play/pause (0x1FE30CF), volume + (0x1FEF807), volume - (0x1FE708F), mute (0x1FEB04F)

26、Attitude sensor - angle / yaw

Postion00

mcookie.getMotionSTH2X('motion',angle, status, 106, 28)
"""
    angle : Angle selection, default is angle, parameter is '0', contains '0' (angle), '2' (angular velocity)
    status : State selection, default is yaw, parameter is ‘Z', contains 'Z' (yaw), 'Y' (pitch), 'X' (roll)
    Return value type : Return value type is float 
    Parameter type: angle, status are all string types     
"""

The parameters 'motion', 106, 28 are fixed values and cannot be modified manually. When angle is '0', the last parameter is 28, and when angle is '2', the last parameter is 16

27、Attitude sensor - acceleration

Postion01

mcookie.getMotionSTH2X('motion','1',status, 106, 4)
"""
    status : Status selection, default is 'before and after', parameter is ‘X', contains 'X' (front and rear), 'Y' (left and right), 'Z' (up and down)
    Return value type : Return value type is float 
    Parameter type : status is a string type
"""

28、 Temperature/humidity sensor

Temp00

mcookie.temperatureSTH2X()
mcookie.humiditySTH2X()
"""
    Port : IIC
    Select: Detect temperature interface (temperatureSTH2X()), humidity detection interface (humiditySTH2X())
    Function : For detecting temperature and humidity
    Return value : The return value type is float type
    Applicable modules : Sensor expansion board
"""

29、Temperature Sensor

Temp01

mcookie.temperatureLM75()
"""
    Port : IIC
    Function : For detecting temperature
    Return value : The return value type is float type
    Applicable modules : Sensor expansion board
"""

30、Gesture distance

Gesture

mcookie.gestureDistance()
"""
    Port : IIC
    Function : Used to measure gesture distance
    Return value : The return value type is int, indicating the actual distance
    Applicable modules : Sensor expansion board
"""

31、Ultrasonic ranging

ultrasonic

mcookie.ultrasonic()
"""
    Port : IIC
    Function : For measuring distance
    Return value : The return value type is int, indicating the actual distance
    Applicable modules : Sensor expansion board
"""