RGB LED


Now we'll turn our attention to lighting an RGB type of LED. In this exercise, you'll learn how to pan through 4096 different colors (mixtures of 16 different levels of red, green and blue).

Just as important from a learning perspective is that we get to use a PIC timer and interrupts for the first time. Both of these features are extraordinarily easy to tame in PIC Micro Pascal, as one look at the source code ought to convince you.

In effect, what's going on here is we'll create three simultaneous pulse trains, each with an independently controllable duty cycle, and all phase locked. By varying the duty cycles, the intensity of the red, green and blue elements within the LED creates different mixes, and hence hues. Here's a scope shot showing those three pulse trains in action:


The actually circuitry is a snap, as you'll note in the schematic here. You might want to individually adjust the resistor values to equalize the color mix.


As usual, there are many comments and hints in the source, so be sure to study it to master the details.

Click to get the source code.
Click to get the schematic PDF.

Next Project: LED Dot Graph -- Direct Drive

2 comments:

  1. Hi,

    recently joined pmp. Thill now, I'm using mikroPascal AVR/"Arduino".
    Didn't find a project about ws2812b-strips, so I'll post my project-videos here. Just some examples of what you can do with ws2812b-strips. Allready got a 5 meter strip funcioning!

    klick ws2812 led strip:

    https://www.youtube.com/channel/UCGdece-f-TRRRMBFn51fk-g/playlists?view_as=subscriber

    Kind regards.

    ReplyDelete