RGBLED

RGBLED

new RGBLED(red, green, blue, active_highopt, initial_valueopt, pwmopt)

Source:
Represents a full color LED component (composed of red, green, and blue LEDs). Connect the common cathode (longest leg) to a ground pin; connect each of the other legs (representing the red, green, and blue anodes) to any GPIO pins. You can either use three limiting resistors (one per anode) or a single limiting resistor on the cathode.
Parameters:
Name Type Attributes Description
red int The GPIO pin that controls the red component of the RGB LED.
green int The GPIO pin that controls the green component of the RGB LED.
blue int The GPIO pin that controls the blue component of the RGB LED.
active_high boolean <optional>
Set to ``true`` (the default) for common cathode RGB LEDs. If you are using a common anode RGB LED, set this to ``false``.
initial_value Array <optional>
The initial color for the RGB LED. Defaults to black ``[0, 0, 0]``.
pwm boolean <optional>
If ``true`` (the default), construct PWMLED instances for each component of the RGBLED. If ``false``, construct regular LED instances, which prevents smooth color graduations.
Throws:
GPIOPinMissing - If one of the pins is not specified.

Extends

Methods

close()

Source:
Overrides:
Close each pin and release for reuse.

is_active() → {boolean}

Source:
Overrides:
Returns:
- If the LED is currently active (not black) then ``true`` otherwise ``false``.
Type
boolean

off()

Source:
Turn the LED off. This equivalent to setting the LED color to black ``[0, 0, 0]``.

on()

Source:
Turn the LED on. This equivalent to setting the LED color to white ``[1, 1, 1]``.

toggle()

Source:
Toggle the state of the device. If the device is currently off (`value` is ``[0, 0, 0[``), this changes it to "fully" on (`value` is ``[1, 1, 1]``). If the device has a specific color, this method inverts the color.

value(valueopt) → {Array}

Source:
Overrides:
Represents the color of the LED as an RGB 3-tuple of ``[red, green, blue]`` where each value is between 0 and 1 if ``pwm`` was ``true`` when the class was constructed (and only 0 or 1 if not).
Parameters:
Name Type Attributes Description
value Array <optional>
If set, the value for each component will be updated.
Throws:
  • OutputDeviceBadValue - If three values are not passed as an array in value.
  • OutputDeviceBadValue - If any of the RGB values are not between 0 and 1.
  • OutputDeviceBadValue - If pwm is false but a value is between 0 and 1.
Returns:
- If ``value`` is ``undefined`` then returns the current value for each component.
Type
Array