adafruit_rgbled
¶
CircuitPython driver for RGB LEDs
Author(s): Brent Rubell
Implementation Notes¶
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
- class adafruit_rgbled.RGBLED(red_pin: Pin | pwmio.PWMOut | PWMChannel, green_pin: Pin | pwmio.PWMOut | PWMChannel, blue_pin: Pin | pwmio.PWMOut | PWMChannel, invert_pwm: bool = False)¶
Create an RGBLED object given three physical pins or PWMOut objects.
Example for setting an RGB LED using an RGB Tuple (Red, Green, Blue):
import board import adafruit_rgbled RED_LED = board.D5 GREEN_LED = board.D6 BLUE_LED = board.D7 # Create a RGB LED object led = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) led.color = (255, 0, 0)
Example for setting an RGB LED using a 24-bit integer (hex syntax):
import board import adafruit_rgbled RED_LED = board.D5 GREEN_LED = board.D6 BLUE_LED = board.D7 # Create an RGB LED object led = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) led.color = 0x100000
Example for setting an RGB LED using a ContextManager:
import board import adafruit_rgbled with adafruit_rgbled.RGBLED(board.D5, board.D6, board.D7) as rgb_led: rgb_led.color = (255, 0, 0)
Example for setting a common-anode RGB LED using a ContextManager:
import board import adafruit_rgbled with adafruit_rgbled.RGBLED(board.D5, board.D6, board.D7, invert_pwm=True) as rgb_led: rgb_led.color = (0, 255, 0)
- Parameters:
red_pin (Union["microcontroller.Pin", PWMOut, "PWMChannel"]) – The connection to the red LED.
green_pin (Union["microcontroller.Pin", PWMOut, "PWMChannel"]) – The connection to the green LED.
blue_pin (Union["microcontroller.Pin", PWMOut, "PWMChannel"]) – The connection to the blue LED.
invert_pwm (bool) – False if the RGB LED is common cathode, True if the RGB LED is common anode. Defaults to False.
- property color: int | Tuple[int, int, int]¶
Sets the RGB LED to a desired color.
- Parameters:
value (ColorBasedColorUnion) – RGB LED desired value - can be a RGB tuple of values 0 - 255 or a 24-bit integer. e.g. (255, 64, 35) and 0xff4023 are equivalent.
- Returns Union[int, Tuple[int, int, int]]:
The current LED color setting.
- Raises:
ValueError – If the input is an int > 0xffffff or is a tuple that does not contain 3 integers of 0 - 255.
TypeError – If the input is not an integer or a tuple.