PWM: RGB LED¶
This is a sample app which drives an RGB LED using PWM.
There are three single-color component LEDs in an RGB LED. Each component LED is driven by a PWM port where the pulse width is changed from zero to a fusion flicker threshold (the minimum flicker rate where the LED is perceived as being steady), causing each component LED to step from dark to max brightness. Three for loops (one for each component LED) generate a gradual range of color changes from the RGB LED, and the sample repeats forever.
The board must have red, green, and blue LEDs connected via PWM output channels.
You will see at least one of these errors if you try to build this sample for an unsupported board:
Unsupported board: red-pwm-led devicetree alias is not defined Unsupported board: green-pwm-led devicetree alias is not defined Unsupported board: blue-pwm-led devicetree alias is not defined
See boards/arm/hexiwear_k64/hexiwear_k64.dts for an example
BOARD.dts file which supports this sample.
No additional wiring is necessary if the required devicetree aliases refer to hardware that is already connected to LEDs on the board.
Otherwise, LEDs should be connected to the appropriate PWM channels.