Chapter 6. Breadboards and LEDs
Like many light bulbs, LEDs can not only be turned on and off; they can be dimmed (or made to look dimmed) as well.
By changing the intensity of LEDs, you can represent the value of a sensor, create cool effects like pulsing and breathing, or signal that your Netduino app has important information to share.
You can also group LEDs together to represent numbers. And you can combine colored LEDs together to form new colors. You can even dim those colored LEDs, generating millions of color combinations.
Changing Intensity
To dim an LED (i.e., change its intensity), you simply turn it on and off quickly. If the LED is on half the time and off half the time, it will appear about half as bright to the human eye. If you turn it on only 10% of the time, it will seem very dim. While it is possible to simply turn LEDs on and off rapidly using looping on and off commands in code, the Netduino’s microcontroller has an integrated feature especially suited for this task. This feature is called Pulse Width Modulation (PWM) and, if you tell it the percentage of time to toggle the LED on, it will automatically dim the LED by pulsing it rapidly. This is all done in the background, which frees up both the microcontroller and your code to focus on more important tasks.
Previously, you turned on and off an LED using the
OutputPort
feature of .NET Micro Framework. Now you’re
ready to update that code to set the LED’s intensity using the PWM feature
instead.
First, you’ll need ...
Get Getting Started with Netduino now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.