- Discrete LEDs
- Dot/Bar LEDs
- Matrix LEDs
- 7-Seg LEDs
- Serial -- Software
- Serial -- Hardware
- RS-232 via the MAX3232
- I2C -- EEPROM
- I2C -- DS1307 Real Time Clock
- 1-Wire -- DS18B20, Powered, Single-Drop
- 1-Wire -- DS18B20, Powered, Multi-Drop
- 1-Wire -- DS18B20, Parasitic, Multi-Drop
- TI Link Protocol -- Calculator Demo
- Infrared Communication
- MIDI -- Output Demo
- MIDI -- Input Demo
- MIDI to Analog Synth
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