rgbled module

This module support common cathode RGB LED.

Object: rgbled

rgbled.version

  • <string>
    version of the this rgbled module.

rgbled.RED

  • <number> = 1
    BIT0

rgbled.GREEN

  • <number> = 2
    BIT1

rgbled.BLUE

  • <number> = 4
    BIT2

rgbled.init(redPin, greenPin, bluePin)

  • redPin <number> : The pin number which support GPIO and it shall be connected to RED pin of the RGB LED.
  • greenPin <number> : The pin number which support GPIO and it shall be connected to GREEN pin of the RGB LED.
  • BluePin <number> : The pin number which support GPIO and it shall be connected to BLUE pin of the RGB LED.
    Initialize the RGB pin numbers to control in this object. This function shall be called before calling rgbled.set() or rgbled.setPattern() functions.

rgbled.set(color)

  • color <number>: Turn on the LED with color value, Bit0(0x01) of the color value is RED, Bit1(0x02) is the GREEN and Bit3(0x04) is the BLUE. The BLUE and GREEN will be tuned on together if the Bit1(0x02) and BIT2(0x04) are set, color = 0x06 (BIT1 + BIT2)

rgbled.setPattern(colorPattern, delay)

  • colorPattern <number[]>: Arrays of the colors, Tune on the array color pattern with delay.
  • delay <number>: Millisecond(ms) delays between the colorPattern.

HW configuration on the breadboard.

rgb_module.PNG

Example code

var rgbled = require('@communix/rgbled').rgbled;

print(rgbled.version);

var pattern = [
  rgbled.RED,
  rgbled.GREEN,
  rgbled.BLUE,
  rgbled.RED | rgbled.GREEN,
  rgbled.GREEN | rgbled.BLUE,
  rgbled.BLUE | rgbled.RED,
  rgbled.RED | rgbled.GREEN | rgbled.BLUE,
  0,
];
//Pin configuration
rgbled.init(0, 1, 2); //R : pin0, G : pin1, B : pin2

// turn on all LEDs
rgbled.set(rgbled.RED | rgbled.GREEN | rgbled.BLUE); //Turn on RED, GREEN and BLUE

// For 1s
delay(1000);

//Start LED pattern.
rgbled.setPattern(pattern, 1000); //Turn on LED pattern with 1000ms delay