Component: LED (Generic, RGB) (LED)

From Flowcode Help
Revision as of 17:50, 9 November 2022 by Wiki bot (talk | contribs)
Jump to navigationJump to search
Author Matrix Ltd
Version 1.3
Category LED


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.

Component Source Code

Please click here for the component source code: FC_Comp_Source_RGB_LED.fcfx

Detailed description

No detailed description exists yet for this component

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

Fc9-comp-macro.png Disable
Disables the RGB LED. It will no longer respond to color changes. 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png Enable
Enables the RGB LED. This must be done before the LED can be lit or the color changed. 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png 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. 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png 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). 
Fc9-u8-icon.png - BYTE red
Red component of RGB LED local to this macro 
Fc9-u8-icon.png - BYTE green
Green component of RGB LED local to this macro 
Fc9-u8-icon.png - BYTE blue
Blue component of RGB LED local to this macro 
Fc9-void-icon.png - VOID Return



Property reference

Fc9-prop-icon.png Properties
Fc9-conn-icon.png Pin Connections
Fc9-type-5-icon.png Red
Pin that the red LED is connected to. 
Fc9-type-5-icon.png Green
Pin that the green LED is connected to. 
Fc9-type-5-icon.png Blue
Pin tha the Blue pin is connected to. 
Fc9-conn-icon.png Misc
Fc9-type-16-icon.png Polarity
Active High: Use for common cathode LEDs - Pin true = LED On. Active Low: Use for common anode LEDs - Pin false = LED On. 
Fc9-type-16-icon.png Color bit size
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. 
Fc9-type-14-icon.png Rollover value
The number of unique colours each R/G/B channel can output. Range: 0 to (Rollover Value - 1). 
Fc9-conn-icon.png Simulation
Fc9-type-17-icon.png 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. 
Fc9-type-16-icon.png Shape
Choose a simple shape for the LED when there is no 'Target' selected. 
Fc9-type-15-icon.png Width
Width of the LED shape. 
Fc9-type-15-icon.png Height
Height of the LED shape. 
Fc9-type-15-icon.png Depth
Depth of the LED shape.