Full color RGB lights

Full color LED light control principle

The full-color LED light is essentially an LED light that integrates red, green, and blue monochromatic illuminants into a small area. When controlling, the three-color lamps output different light intensities, which can be mixed to obtain For different colors, the principle of color mixing is the same as that of the three primary colors of light.

For example, if the red, green and blue lights can control the output light intensity to [0:255] levels, then the light can be mixed to obtain all colors represented by RGB888 (including pure black represented by all three RGB lamps being off). ).

RGB light is a kind of full-color LED light. When the basic control principle of LED is introduced earlier, it can only control the on and off of RGB three-color light, that is, each RGB light has two levels of [0:1], so it can only be combined. 8 colors.

To use STM32 to control LED lights to output various brightness levels, it can be achieved by controlling the duty cycle of the output pulse.
write picture description here
The example diagram lists pulse waveforms with the same period and duty cycle of 100%, 80%, 50 and 20% respectively. If such pulses are used to control the LED lights, the proportion of the LED lights on and off can be controlled. If the frequency of the pulse is increased, the LED light will switch on and off at a high frequency. Due to the persistence of vision effect, the human eye cannot see the flickering phenomenon caused by the switching of the LED light, but feels that when the LED light is controlled by pulses with different duty ratios difference in brightness. That is, in a single control cycle, the longer the average time of the LED light on, the higher the brightness, and vice versa. Divide the duty cycle of the pulse signal into 256 levels, which can be used to control the LED light to output 256 kinds of brightness, and use three such signals to control the RGB light to get the effect of 256*256*256 kinds of color mixing. To control the duty cycle, you can directly use the PWM function of the STM32 timer.

software design

The essence of controlling the color of the RGB lights is to control the duty cycle of the output pulses of each PWM channel, and the duty cycle can be modified by setting the output comparison register value of the corresponding channel of the timer, and because the timer has divided a single control pulse cycle into [0: 255] copies, and then when controlling, just assign the color value of each channel of RGB888 to the output comparison register directly.
write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325811263&siteId=291194637