ByteSwitchUnit

Unit ByteSwitch is an 8-switch touch switch input unit equipped with 8 switch inputs and 9 WS2812C RGB LEDs. It uses the STM32 microcontroller and supports I2C communication. The board includes two Port A interfaces and supports cascading multiple Unit ByteSwitch modules, making it suitable for complex systems. It can achieve switch input detection and dynamic lighting feedback, ideal for smart home control, gaming devices, educational platforms, industrial status displays, and interactive exhibitions.

Support the following products:

ByteSwitchUnit

class ByteSwitchUnit

Constructors

class ByteSwitchUnit(i2c, address)

Initialize the ByteSwitchUnit with a specified I2C address.

参数:
  • i2c (I2C) – The I2C interface instance for communication.

  • address (int) – The I2C address of the ByteSwitchUnit, default is 0x46.

UIFLOW2:

init.png

Methods

ByteSwitchUnit.get_byte_switch_state() int

Get the status of all switchs as an integer, where each bit represents the state of each switch.

UIFLOW2:

get_byte_switch_status.png

ByteSwitchUnit.get_switch_state(num) bool

Get the state of a specific switch.

参数:

num (int) – The index of the switch (0-7).

UIFLOW2:

get_switch_state.png

ByteSwitchUnit.get_led_show_mode() bool

Get the current LED show mode.

UIFLOW2:

get_led_show_mode.png

ByteSwitchUnit.set_led_show_mode(mode)

Set the LED show mode.

参数:

mode (int) –

The LED show mode to set.

Options:
  • BYTEBUTTON_LED_USER_MODE: 0

  • BYTEBUTTON_LED_SYS_MODE: 1

UIFLOW2:

set_led_show_mode.png

ByteSwitchUnit.set_led_brightness(num, brightness)

Set the brightness of a specific LED.

参数:
  • num (int) – The index of the LED (0-7).

  • brightness (int) – The brightness level (0-255).

UIFLOW2:

set_led_brightness.png

ByteSwitchUnit.get_led_brightness(num) int

Get the brightness of a specific LED.

参数:

num (int) – The index of the LED (0-7).

UIFLOW2:

get_led_brightness.png

ByteSwitchUnit.set_led_color(num, color, led_show_mode, btn_is_pressed)

Set the color of a specific LED.

参数:
  • num (int) – The index of the LED (0-7).

  • color (int) – The RGB888 color value to set.

  • led_show_mode (int) – The LED show mode, default is BYTEBUTTON_LED_SYS_MODE.

  • btn_is_pressed (bool) – Whether the switch is pressed (affects color in SYS mode).

UIFLOW2:

set_led_color.png

ByteSwitchUnit.get_led_color(num, led_show_mode, btn_is_pressed) int

Get the color of a specific LED.

参数:
  • num (int) – The index of the LED (0-7).

  • led_show_mode (int) – The LED show mode, default is BYTEBUTTON_LED_SYS_MODE.

  • btn_is_pressed (bool) – Whether the switch is pressed (affects color in SYS mode).

UIFLOW2:

get_led_color.png

ByteSwitchUnit.set_indicator_brightness(brightness)

Set the brightness of the indicator LED.

参数:

brightness (int) – The brightness level (0-255).

UIFLOW2:

set_indicator_brightness.png

ByteSwitchUnit.get_indicator_brightness() int

Get the brightness of the indicator LED.

UIFLOW2:

get_indicator_brightness.png

ByteSwitchUnit.set_indicator_color(color)

Set the color of the indicator LED in RGB888 format.

参数:

color (int) – The RGB888 color value to set.

UIFLOW2:

set_indicator_color.png

ByteSwitchUnit.get_indicator_color() int

Get the color of the indicator LED in RGB888 format.

UIFLOW2:

get_indicator_color.png

ByteSwitchUnit.rgb888_to_rgb233(color)

Convert an RGB888 color value to RGB233 format.

参数:

color (int) – The RGB888 color value as a 32-bit integer.

UIFLOW2:

rgb888_to_rgb233.png

ByteSwitchUnit.set_rgb233(num, color)

Set the color of a specific LED in RGB233 format.

参数:
  • num (int) – The index of the LED (0-7).

  • color (int) – The RGB233 color value to set.

UIFLOW2:

set_rgb233.png

ByteSwitchUnit.get_rgb233(num)

Get the color of a specific LED in RGB233 format.

参数:

num (int) – The index of the LED (0-7).

UIFLOW2:

get_rgb233.png

ByteSwitchUnit.set_irq_enable(enable)

Enable or disable IRQ functionality.

参数:

enable (bool) – Whether to enable (True) or disable (False) IRQ.

UIFLOW2:

set_irq_enable.png

ByteSwitchUnit.get_irq_enable()

Get the current IRQ enable status.

UIFLOW2:

get_irq_enable.png

ByteSwitchUnit.save_to_flash()

Save the current user settings to flash.

UIFLOW2:

save_to_flash.png

ByteSwitchUnit.get_firmware_version() int

Get the firmware version of the ByteSwitchUnit.

UIFLOW2:

get_firmware_version.png

ByteSwitchUnit.set_i2c_address(new_addr)

Set a new I2C address for the ByteSwitchUnit.

参数:

new_addr (int) – The new I2C address to set. Must be in the range 0x08 to 0x78.

UIFLOW2:

set_i2c_address.png

ByteSwitchUnit.get_i2c_address() int

Get the current I2C address of the ByteSwitchUnit.

UIFLOW2:

get_i2c_address.png