跳转至

LedDriver

robodyno.components.can_bus.led_driver

Led driver.

The led driver is a device that provides a simple interface to control the ws2812b led strip.

Examples:

>>> from robodyno.components import LedDriver
>>> from robodyno.interfaces import CanBus
>>> can = CanBus()
>>> strip = LedDriver(can)
>>> strip.set_color(id_=0, color=(255, 0, 0))
>>> strip.blink(1, color=(0, 255, 0), period=0.5)
>>> strip.breathe((2, 3), color=(0, 0, 255), period=0.5)
>>> strip.marquee((4, 7), color=(255, 255, 0), period=1.0)
>>> strip.clear()
>>> can.disconnect()

LedDriver

Bases: CanBusDevice

Led driver.

属性:

名称 类型 描述
id int

Device id.

type Model

Device type.

fw_ver float

Firmware version.

__init__(can, id_=51)

Initializes the led driver.

参数:

名称 类型 描述 默认
can CanBus

Can bus instance.

必需
id_ int

Device id.

51

引发:

类型 描述
ValueError

If the device id is invalid.

config_can_bus(new_id=None, bitrate=1000000)

Configures the can bus.

参数:

名称 类型 描述 默认
new_id int

New device id.

None
bitrate int

Can bus bitrate.

1000000

引发:

类型 描述
ValueError

If the new id is invalid.

set_color(id_, color)

Sets the color of the led.

参数:

名称 类型 描述 默认
id_ int | tuple

Led id(s). If it is a tuple, it will set the color of multiple leds starting from the first id in the tuple to the second id in the tuple.

必需
color tuple

Led(s) color.

必需

Lets the led blink.

参数:

名称 类型 描述 默认
id_ int | tuple

Led id(s). If it is a tuple, it will blink multiple leds starting from the first id in the tuple to the second id in the tuple.

必需
color tuple

Led(s) color.

必需
period float

Half of the blink period in seconds. The led will be on for period seconds and off for period seconds.

必需

breathe(id_, color, period)

Lets the led breathe.

参数:

名称 类型 描述 默认
id_ int | tuple

Led id(s). If it is a tuple, it will breath multiple leds starting from the first id in the tuple to the second id in the tuple.

必需
color tuple

Led(s) color.

必需
period float

Half of the breath period in seconds. The led will be on for period seconds and off for period seconds.

必需

marquee(id_, color, period)

Turns on the led one by one and then turns off one by one.

参数:

名称 类型 描述 默认
id_ tuple

Led ids. It will control multiple leds turning on and off one by one starting from the first id in the tuple to the second id in the tuple.

必需
color tuple

Led(s) color.

必需
period float

Half of the marquee period in seconds. The led will be on for period seconds and off for period seconds.

必需

引发:

类型 描述
ValueError

If the id_ is not a tuple.

clear()

Turns off all the leds.