Tri-Colored LED with a Single Port Pin


As promised, here is a better way to do the tri-colored LED thing, in that it frees up a port pin compared to Exercise 010. Obviously, the way to fade from red to orange to green is by using pulse width modulation (PWM), with the red element being driven by one pulse train, and the green element by the complement of that pulse train. So, we'll simply use a transistor configured as an inverter to make that complement.


As before, I've used a slightly modified PWM unit in the code (which is included with the source files). The only thing I changed was making it easier to configure PWM from the calling program simply by setting a couple compile parameters.

Note that the microcontroller is now running at 1 MHz so that the PWM frequency stays within proper limits and with decent resolution.

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

Next project: Tri-Colored LED Using Internal Comparator 

No comments:

Post a Comment