LEDController¶
- class bbl.leds.LEDController(led_channel, *args, **kwargs)[source]¶
Bases:
objectA singleton class to control an LED.
- __init__(led_channel)[source]¶
Initializes the LEDController instance for controlling an LED based on the specified channel. This method sets up the LED effects, initializes the current effect index, repeat count, duration, and start time. It then maps the provided LED channel to its corresponding pin number and initializes the NeoPixel object.
- Parameters:
led_channel (str) – The channel number of the LED, either “LED1” or “LED2”.
- Raises:
ValueError – If the provided led_channel is not “LED1” or “LED2”.
Example
>>> led_controller = LEDController("LED1") >>> # The LEDController instance is now initialized with LED1's pin configuration.
Note
The led_channel parameter should be a string matching either “LED1” or “LED2”. The actual pin numbers for “LED1” and “LED2” are defined in the led_pins_map dictionary. The NeoPixel object is initialized with the pin number and the number of LEDs (4 in this case).
See also
NeoPixel: The class used to control the NeoPixel LED strip.
- set_led_effect(mod, duration, repeat_count, led_index, rgb)[source]¶
Sets the LED effect. This method configures the LED with the specified effect, duration, repeat count, LED index, and RGB color.
- Parameters:
mod (int) – The index of the effect to set. - mod = 0: solid effect - mod = 1: blink effect - mod = 2: breathing effect
duration (int) – The duration of the effect in milliseconds.
repeat_count (int) – The number of times to repeat the effect. Must be between 0 and 255. A value of 255( 0xFF ) represents infinite repetition.
led_index (int) – The index of the LED to control. Each bit represents the index of an LED (e.g., the first bit represents OUT1, the second bit represents OUT2).
rgb (int) – The RGB color value of the LED in hexadecimal.
- Returns:
None
- Raises:
ValueError – If mod, repeat_count, or led_index is out of range, or if rgb is not a valid hexadecimal color code.
Example
>>> # Solid red on LED1 for 1 second >>> set_led_effect(0, 1000, 5, 0b0001, 0xFF0000) >>> # Blink green on LED1 and LED2 indefinitely >>> set_led_effect(1, 500, 255, 0b0011, 0x00FF00)