RGB Control
Overview
This section contains all components and utilities for RGB Control.
Components
| Item | Type | Description |
|---|---|---|
| rgb | Property | RGB controller for managing device lighting effects. |
| RGBController | Class | Controller for managing RGB lighting effects on the Decker device. |
rgb
RGB controller for managing device lighting effects.
Control the 8 RGB LEDs on the Decker device with various effects, colors, brightness levels, and animation speeds.
RGBController
Controller for managing RGB lighting effects on the Decker device.
The Decker device features 8 RGB LEDs that can display various lighting effects. This controller provides methods to control the lighting effects, colors, brightness, and animation speed.
Example
import Plugin, { runPlugin } from '@dotmatrixlabs/dotx-plugin-sdk';
export default class RGBPlugin extends Plugin {
async onLoad() {
// Turn off RGB lights
await this.rgb.turnOff();
// Set static red color at 50% brightness
await this.rgb.setEffect('static', 50, 50, '#FF0000');
// Enable rainbow effect
await this.rgb.setEffect('rainbow', 75, 100, '#FFFFFF');
// Adjust brightness only
await this.rgb.setBrightness(80);
// Change color only
await this.rgb.setColor('#00FF00');
}
}Properties
- effects (any): Available RGB lighting effects.
Methods
| Method | Parameters | Description |
|---|---|---|
getAvailableEffects() | - | Get the list of available RGB effects. |
getCurrentState() | - | Get the current RGB state. |
setBrightness() | brightness: number | Update only the brightness of the current RGB effect. |
setColor() | color: string | Update only the color of the current RGB effect. |
setEffect() | effectName: RGBEffect, speed: number, brightness: number, color: string | Set a complete RGB lighting effect with all parameters. |
setSpeed() | speed: number | Update only the animation speed of the current RGB effect. |
turnOff() | - | Turn off all RGB lighting. |
getAvailableEffects()
getAvailableEffects(): anyGet the list of available RGB effects.
Returns an array of all supported RGB effect names that can be used with the setEffect() method.
Returns:
any - Array of available effect names
Example:
const effects = this.rgb.getAvailableEffects();
console.log('Available effects:', effects);
// Output: ['rainbow', 'static', 'off', 'lightningStorm', 'candle', 'perimeter', 'breathing']
// Use in a settings dropdown
settings.addSelect('rgbEffect')
.setLabel('RGB Effect')
.setOptions(
this.rgb.getAvailableEffects().map(effect => ({
value: effect,
label: effect.charAt(0).toUpperCase() + effect.slice(1)
}))
);getCurrentState()
getCurrentState(): anyGet the current RGB state.
Returns the current effect, speed, brightness, and color settings.
Returns:
any - Object containing current RGB settings
Example:
const state = this.rgb.getCurrentState();
console.log('Current effect:', state.effect);
console.log('Current brightness:', state.brightness);
console.log('Current color:', state.color);
console.log('Current speed:', state.speed);setBrightness()
setBrightness(brightness: number): PromiseUpdate only the brightness of the current RGB effect.
This is a convenience method that updates brightness while keeping the current effect, speed, and color unchanged.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
brightness | number | Yes | LED brightness from 0 (off) to 100 (maximum) |
Returns:
Promise - Promise that resolves when the brightness is updated
Example:
// Dim the lights to 25%
await this.rgb.setBrightness(25);
// Set to full brightness
await this.rgb.setBrightness(100);
// Turn lights almost off but not completely
await this.rgb.setBrightness(5);setColor()
setColor(color: string): PromiseUpdate only the color of the current RGB effect.
This is a convenience method that updates color while keeping the current effect, speed, and brightness unchanged.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
color | string | Yes | Color in hex format (e.g., '#FF0000' for red) |
Returns:
Promise - Promise that resolves when the color is updated
Example:
// Change to red
await this.rgb.setColor('#FF0000');
// Change to blue
await this.rgb.setColor('#0000FF');
// Change to purple
await this.rgb.setColor('#FF00FF');
// Change to warm white
await this.rgb.setColor('#FFE4B5');setEffect()
setEffect(effectName: RGBEffect, speed: number, brightness: number, color: string): PromiseSet a complete RGB lighting effect with all parameters.
Controls the device's 8 RGB LEDs with the specified effect, speed, brightness, and color.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
effectName | RGBEffect | Yes | The lighting effect to apply |
speed | number | Yes | Animation speed from 1 (fastest) to 100 (slowest) |
brightness | number | Yes | LED brightness from 0 (off) to 100 (maximum) |
color | string | Yes | Color in hex format (e.g., '#FF0000' for red, '#00FF00' for green) |
Returns:
Promise - Promise that resolves when the effect is applied
Example:
// Set static blue color at medium brightness and speed
await this.rgb.setEffect('static', 50, 75, '#0000FF');
// Set rainbow effect at fast speed and full brightness
await this.rgb.setEffect('rainbow', 10, 100, '#FFFFFF');
// Set breathing effect with purple color (slow)
await this.rgb.setEffect('breathing', 80, 80, '#FF00FF');
// Set candle flicker effect (medium speed)
await this.rgb.setEffect('candle', 50, 70, '#FFA500');setSpeed()
setSpeed(speed: number): PromiseUpdate only the animation speed of the current RGB effect.
This is a convenience method that updates speed while keeping the current effect, brightness, and color unchanged.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
speed | number | Yes | Animation speed from 1 (fastest) to 100 (slowest) |
Returns:
Promise - Promise that resolves when the speed is updated
Example:
// Set to fast animation
await this.rgb.setSpeed(10);
// Set to slow animation
await this.rgb.setSpeed(90);
// Set to medium speed
await this.rgb.setSpeed(50);turnOff()
turnOff(): PromiseTurn off all RGB lighting.
This is a convenience method that sets the effect to 'off'. Equivalent to calling setEffect('off', 0, 0, '#000000').
Returns:
Promise - Promise that resolves when the lights are turned off
Example:
// Turn off the RGB lights
await this.rgb.turnOff();
// In an onUnload handler
async onUnload() {
await this.rgb.turnOff();
console.log('Plugin unloading, RGB lights turned off');
}