Skip to content

Peripherals

Overview

Peripheral modules allow applications to read status or perform operations on the Vobot Dock's hardware.

Buzzer

peripherals.buzzer.enabled

  • Description: Whether the device buzzer is enabled (whether the buzzer is allowed to operate).
  • Value Range: False (not allowed) or True (allowed).

peripherals.buzzer.acquire()

  • Description: Gets permission to control the device's buzzer.
  • Return Value: False (retrieval failed) or True (retrieval successful).

peripherals.buzzer.release()

  • Description: Releases permission to control the device's buzzer.
  • Return Value: False (release failed) or True (release successful).

peripherals.buzzer.set_freq(freq)

  • Description: Control the frequency of the device buzzer so that the buzzer can emit different sounds.
  • Parameters:
    • freq (int):
      • Value Range: [100 ~ 8000].
  • Return Value: False (setup failed) or True (setup successful).

peripherals.buzzer.set_volume(vol)

  • Description: Controls the volume at which the device buzzer sounds.
  • Parameters:
    • vol (int):
      • Value Range: [0 ~ 100].
      • Note: When vol is 0, it means the buzzer stops buzzing.
  • Return Value: False (setup failed) or True (setup successful).

Usage examples

import peripherals

# Check whether the buzzer is enabled
peripherals.buzzer.enabled

# Get buzzer control
peripherals.buzzer.acquire()

# Set buzzer frequency
peripherals.buzzer.set_freq(400)

# Set buzzer volume
peripherals.buzzer.set_volume(100)

# Release buzzer control
peripherals.buzzer.release()

LED Clock

peripherals.led_clock.acquire()

  • Description: Get permission to control the device's LED clock.
  • Return Value: False (retrieval failed) or True (retrieval successful).
  • Note: After execution, the device will no longer run the system's built-in LED clock light effect.

peripherals.led_clock.release()

  • Description: Releases permission to control the device's LED clock.
  • Return Value: False (release failed) or True (release successful).
  • Note: After execution, the device will continue to run the system's built-in LED clock light effect.

peripherals.led_clock.set_display(ordinal, data)

  • Description: Select the LED clock light group to be displayed and set the display effect.
  • Parameters:
    • ordinal (int):
      • Description: Select the corresponding lamp group (1-6) on the LED clock array that needs to be set.
      • Lamp set 1-4:
        • Each light group controls a different digital light '8'.
        • Each light group contains 7 LED lights, and the lighting of a light group is controlled by one byte (8 bits).
        • Among the 8 bits: the lower 7 bits control the 7 segments of the number.
        • The 8th bit of lamp group 4 controls ':'.
      • Lamp set 5:
        • Control week lamps and 'PM'.
        • bit 1-7: 'MON' ... 'SUN'.
        • bit 8: 'PM'.
      • Lamp set 6:
        • Control the symbol light. The symbol light is only controlled through bit 1-4.
        • bit 1: '.'.
        • bit 2: '%'.
        • bit 3: '℃'.
        • bit 4: '℉'.
    • data (int):
      • Description: Display content corresponding to each light group.
      • Bit value: 0 means off, 1 means on.
      • In light groups 1-4, the corresponding values of digital text are as follows:
        • Number '0': 0x5F.
        • Number '1': 0x06.
        • Number '2': 0x3B.
        • Number '3': 0x2F.
        • Number '4': 0x66.
        • Number '5': 0x6D.
        • Number '6': 0x7D.
        • Number '7': 0x07.
        • Number '8': 0x7F.
        • Number '9': 0x6F.
  • Return Value: False (setup failed) or True (setup successful).

peripherals.led_clock.brightness(light_level=None)

  • Description: Get or set the brightness of the device LED clock.
  • Parameters:
    • light_level (int, optional): The brightness percentage (0-100). If provided, sets the LED clock brightness to the specified percentage. If not provided, returns the current LED clock brightness.
  • Return Value:
    • If light_level is provided: Returns True if the operation is successful, or False if it fails.
    • If light_level is not provided: Returns the current LED clock brightness percentage.
  • Precautions: The adjusted brightness is temporary and will revert to the original brightness once the permission is released or the application is closed.

Usage examples

import peripherals

# Get LED clock control rights
peripherals.led_clock.acquire()

# Set LED clock display
peripherals.led_clock.set_display(1, 0x7F)
peripherals.led_clock.set_display(2, 0x7F)
peripherals.led_clock.set_display(3, 0x7F)
peripherals.led_clock.set_display(4, 0xFF)
peripherals.led_clock.set_display(5, 0xFF)
peripherals.led_clock.set_display(6, 0xFF)

# Set LED clock brightness
peripherals.led_clock.brightness(100)

# Get LED clock brightness
peripherals.led_clock.brightness()

# Release LED clock control
peripherals.led_clock.release()

Ambient Light

peripherals.ambient_light.count

  • Description: The number of lamp beads inside the device's ambient light.

peripherals.ambient_light.acquire()

  • Description: Gets permission to control the device's ambient light.
  • Return Value: False (retrieval failed) or True (retrieval successful).
  • Note: After execution, the device will no longer run the system's built-in ambient light effect.

peripherals.ambient_light.release()

  • Description: Releases permission to control the device's ambient light.
  • Return Value: False (release failed) or True (release successful).
  • Note: After execution, the device will continue to run the system's built-in ambient light effect.

peripherals.ambient_light.set_color(buffer, repeat=True)

  • Description: Set the color of the ambient light.
  • Parameters:
    • buffer (list):
      • Description: A list of RGB color values, such as [(255, 0, 0), (0, 255, 0), (0, 0, 255)]. Each RGB value should be in the range [0-255], representing colors like red (255, 0, 0), green (0, 255, 0), and blue (0, 0, 255).
    • repeat (bool):
      • Description: Indicates whether to display the colors in the buffer in a loop.
      • Value:
        • True: The device will continuously display the colors in the buffer until the permission is released or this function is called again.
        • False: The device will display the colors in the buffer only once.
  • Return Value: True if the colors are successfully set, or False if the list contents are incorrect.
  • Precautions:
    • If the buffer length is less than or equal to the number of LEDs in the device's ambient light, the buffer is automatically repeated to match the number of LEDs.
    • If the buffer length is greater than the number of LEDs in the device's ambient light, only the initial segment of the buffer matching the number of LEDs is used.

peripherals.ambient_light.brightness(light_level=None)

  • Description: Get or set the brightness of the ambient light.
  • Parameters:
    • light_level (int, optional): The brightness percentage (0-100). If provided, sets the ambient light brightness to the specified percentage. If not provided, returns the current ambient light brightness.
  • Return Value:
    • If light_level is provided: Returns True if the operation is successful, or False if it fails.
    • If light_level is not provided: Returns the current ambient light brightness percentage.
  • Precautions: The adjusted brightness is temporary and will revert to the original brightness once the permission is released or the application is closed.

Usage examples

import peripherals

# Get ambient light control rights
peripherals.ambient_light.acquire()

# Get the number of lamp beads of the ambient light
peripherals.ambient_light.count

# Set ambient light color
peripherals.ambient_light.set_color([(255, 0, 0)], True)

# Set ambient light brightness
peripherals.ambient_light.brightness(100)

# Get ambient light brightness
peripherals.ambient_light.brightness()

# Release ambient light control
peripherals.ambient_light.release()

Screen

peripherals.screen.brightness(light_level=None)

  • Description: Get or set the brightness of the device screen.
  • Parameters:
    • light_level (int, optional): The brightness percentage (0-100). If provided, sets the screen brightness to the specified percentage. If not provided, returns the current screen brightness.
  • Return Value:
    • If light_level is provided: Returns True if the operation is successful, or False if it fails.
    • If light_level is not provided: Returns the current screen brightness percentage.
  • Precautions: The adjusted brightness is temporary and will revert to the original brightness once the application is closed.

peripherals.screen.screen_resolution

  • Description: Get the resolution of the device screen.
  • Return Value: The resolution of the device screen.

Usage examples

import peripherals

# Set screen brightness
peripherals.screen.brightness(50)

# Get screen brightness
peripherals.screen.brightness()

# Get screen resolution
peripherals.screen.screen_resolution