adafruit_rgbled

CircuitPython driver for RGB LEDs

  • Author(s): Brent Rubell

Implementation Notes

Software and Dependencies:

class adafruit_rgbled.RGBLED(red_pin, green_pin, blue_pin, invert_pwm=False)

Creates a RGBLED object given three physical pins or PWMOut objects.

Parameters
  • red_pin – The physical pin connected to a red LED anode.

  • green_pin – The physical pin connected to a green LED anode.

  • blue_pin – The physical pin connected to a blue LED anode.

  • invert_pwm (bool) – False if the RGB LED is common cathode, true if the RGB LED is common anode.

Example for setting a RGB LED using a 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 a 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 a RGB LED object
led = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
led.color = 0x100000

Example for setting a 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)
property color

Returns the RGB LED’s current color.

deinit()

Turn the LEDs off, deinit pwmout and release hardware resources.