LED Heart PWM Fading

Jump To:
PWM Theory
           In order to control the actual brightness of the LED, we will send it a PWM signal PWM stands for pulse with modulation. Any PWM signal has three core qualities:
  1. Frequency
  2. Duty Cycle
  3. Amplitude

These three qualities tell us what type of PWM signal to expect and we will then be able to project its effect on our system. Below are a few examples of PWM signals with their associated qualities listed out.

Some PWM Examples

           The type of PWM signal we'll be generating will ultimately look like the pictures above. We'll be shooting for a 60-120 Hz frequency range, with an amplitude of +5v (because our system uses +5v). The duty cycle, however, will vary between 0% (fully-off state) and 100% (fully-on state).

Lighting an LED via PWM
           So, if we send any of the signals seen above into an LED, what do we expect should happen? Well, the LED turns on for the short duration of the pulse. Since we will choose an output frequency of between 60-120 Hz, the LED will appear to be a solid color because of persistence of vision. The brightness, however, will be controlled purely by the duty cycle %. The animation below gives you an idea of the effect of different PWM duty cycles input into an LED.

           So now that we've learned a simple way to fade LEDs and control their intensity, let's see how we're going to use this knowledge to control different patterns of the LEDs shaped like a heart.