Component: LED (Generic, RGB) (Outputs: LEDs)

From Flowcode Help
Jump to navigationJump to search


Author Matrix Ltd
Version 1.3 (Release)
Category Outputs: LEDs


Image LED (Generic, RGB) component

An LED with red, green and blue elements that can be mixed together to produce almost any colour at any brightness.

This component can be used as a base to create child components

Image The component LED (RGB, PCB) is inherited from this.

Examples

Tricolour LEDs generally have four pins and come in both common anode and common cathode configurations and must be wired to suit. The RGBLED component has a property allowing you to configure which LED type your using.

TriLED.jpg


An active high LED will light when the microcontroller pin is outputting a logic 1 and be off when the microcontroller pin is outputting a logic 0 or in input mode.


An active low LED will light when the microcontroller pin is outputting a logic 0 and be off when the microcontroller pin is outputting a logic 1 or in input mode.


Six pin tricolour LEDs can simply be treated as three individual standards LEDs.


The series resistor acts to protect each individual LED from damage due to excess current. The value of resistor used can be changed based on the brightness of the LED and power consumption. Usually the three colour LEDs have different characteristics from each other so a different protection resistor should be provided for each LED to balance the LEDs output.


This LED Calculator tool is a good resource for calculating the correct LED series protection resistor.

LED Resistor Calculator Tool



This example for the RGB LED uses three analogue sliders to set the output colour of the LED. FC6 Icon.png RGB LED Example The LED Colour is output to the LED using the Timer interrupt which calls the RGB LED Tick function.


The RGB LED properties include a setting for "Colour Bit Size" which sets the period for the LED colour PWM. The "Rollover Value" property shows the number of interrupts required for each PWM period so the timer interrupt should be running fast enough to allow the LED to output several periods per second. Persistence of vision can normally no longer detect any flickering light above approx 24Hz.


For a constant none flickering LED you can work out the minimum interrupt frequency like this.

30Hz * Rollover Value = Minimum interrupt frequency

30Hz * 256 = 7680Hz

60Hz * 64 = 3840Hz


Each LED colour channel can be set from 0 (minimum) to the rollover value - 1 (maximum). Therefore with a colour channel bit size of 8 there are theoretically 16777216 colours available 2^(8*3). With a colour bit size of 4 the available number of colours that can be generated drops to 4096, 2^(4*3).

Downloadable macro reference

Disable

Disables the RGB LED. It will no longer respond to color changes.

Parameters

This macro has no parameters


Return value

This call does not return a value


Enable

Enables the RGB LED. This must be done before the LED can be lit or the color changed.

Parameters

This macro has no parameters


Return value

This call does not return a value


Tick

Call this macro at regular intervals to illuminate the LED with the chosen color.

Turns each pin on and off to generate a simple PWM signal for each color - when done rapidly, this gives the illusion of the chosen color.

Parameters

This macro has no parameters


Return value

This call does not return a value


SetColor

Set the target color for the LED. Each of the Red, Blue and Green channels can be set to any value from 0 (off) to 255 (full brightness).

Parameters

BYTE red
Red component of RGB LED local to this macro
BYTE green
Green component of RGB LED local to this macro
BYTE blue
Blue component of RGB LED local to this macro


Return value

This call does not return a value


Simulation macro reference

This component does not contain any simulation macros


Property reference

Red

This property is of type Single digital pin and can be referenced with the variable name red_pin.

Pin that the red LED is connected to.

Green

This property is of type Single digital pin and can be referenced with the variable name green_pin.

Pin that the green LED is connected to.

Blue

This property is of type Single digital pin and can be referenced with the variable name blue_pin.

Pin tha the Blue pin is connected to.

Polarity

This property is of type Fixed list of ints and can be referenced with the variable name polarity.

Active High: Use for common cathode LEDs - Pin true = LED On.

Active Low: Use for common anode LEDs - Pin false = LED On.

Color bit size

This property is of type Fixed list of ints and can be referenced with the variable name colorbitsize.

Color bit depth. Sets the resolution of the virtual PWM signals driving the LEDs.

Lower values mean that the 'Tick' macro can be called less often, but reduced the number of

colours that can be created.

Rollover value

This property is of type Signed integer and can be referenced with the variable name rollover.

The number of unique colours each R/G/B channel can output.

Range: 0 to (Rollover Value - 1).

Target

This property is of type Panel object and can be referenced with the variable name target.

Create custom LED shapes by pointing this property at any object on your panel.

This also works with groups of objects - all children of the group will change color.

Shape

This property is of type Fixed list of ints and can be referenced with the variable name Shape.

Choose a simple shape for the LED when there is no 'Target' selected.

Width

This property is of type Floating point and can be referenced with the variable name Width.

Width of the LED shape.

Height

This property is of type Floating point and can be referenced with the variable name Height.

Height of the LED shape.

Depth

This property is of type Floating point and can be referenced with the variable name Depth.

Depth of the LED shape.