跳转至

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.

Attributes:

Name Type Description
id int

Device id.

type Model

Device type.

fw_ver float

Firmware version.

__init__(can, id_=51)

Initializes the led driver.

Parameters:

Name Type Description Default
can CanBus

Can bus instance.

required
id_ int

Device id.

51

Raises:

Type Description
ValueError

If the device id is invalid.

config_can_bus(new_id=None, bitrate=1000000)

Configures the can bus.

Parameters:

Name Type Description Default
new_id int

New device id.

None
bitrate int

Can bus bitrate.

1000000

Raises:

Type Description
ValueError

If the new id is invalid.

set_color(id_, color)

Sets the color of the led.

Parameters:

Name Type Description Default
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.

required
color tuple

Led(s) color.

required

Lets the led blink.

Parameters:

Name Type Description Default
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.

required
color tuple

Led(s) color.

required
period float

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

required

breathe(id_, color, period)

Lets the led breathe.

Parameters:

Name Type Description Default
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.

required
color tuple

Led(s) color.

required
period float

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

required

marquee(id_, color, period)

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

Parameters:

Name Type Description Default
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.

required
color tuple

Led(s) color.

required
period float

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

required

Raises:

Type Description
ValueError

If the id_ is not a tuple.

clear()

Turns off all the leds.