Página 7 - Primeros pasos con la Tarjeta Arduino

A push-button LED that fades on / off
In this example, pressing the button makes the LED light up... BUT, the LED fades in and fades out giving you a more cool, organic
effect (like you see on consumer devices).
The circuit is very simple (just a button and an LED). The cool fading bahavior is done with code. When you get into the code, you
will see that there is a function called Quad_easeInOut(). This is adapted from a set of functions provided by Robert Penner. These
functions do something called easing -- which means to ease in or out of an animation. But you can use easing equations for all
sorts of things. They are valuable anytime you want to smooth out how something goes from one state to another. In our circuit,
we are easing the on / off of the LED.
A note about LEDs: They don't really fade well. What I mean is that if you try to control the brightness of an LED by simply
reducing current, the LED will get somewhat less bright. But eventually, the LED simply shuts off. In order to get good fade
control, we use an ability of the Arduino board called Pulse-Width Modulation or PWM. When you use PWM it means that the
output is at full voltage, but it simulates lower voltages by pulsing the voltage at different rates. Notice that only certain digital pins
can be enabled for PWM -- pins numbered 3, 5, 6, 9, 10, 11.
Parts List
LED
push button
Arduino (in this example, Duemillanove)
Assembly Steps
Connect the ground port on the Arduino board to one of the long rows of holes on the breadboard -- this makes that row
ground (0v).
Connect the 5v port on the Arduino board to one of the other rows of holes on the breadboard -- this makes that row
source voltage (5v).
Connect one leg of the button to both digital pin 8 and ground through a 10k resistor, while the other leg is connected to
source voltage.
Connect the cathode (negative) leg of the LED to ground, and connect the anode (positive) leg of the LED to digital pin 9
on the Arduino board.
Image developed using Fritzing.