Página 8 - Primeros pasos con la Tarjeta Arduino

Arduino Code
/*
This script uses a button to fade an LED -- with an easing equation for smoothness.
This script allows you to use a button to turn an LED on and off (with fading).
We use digitalRead() to get the value from the button.
We use analogWrite() to set the brightness of the LED.
We use an easing equation (thanks to Robert Penner) to make the fading smooth.
We use a timer to allow us to have a specific clock speed (see note below).
The circuit:
*
LED attached from digital pin 9 to ground.
*
Button with one leg connected to digital pin 8 and ground through a 10k resistor, while the other leg is connected to source voltage.
created 2010
by Andrew Frueh
I built this code starting with "Fading" from Arduino examples - 1 Nov 2008, By David A. Mellis
*/
//
You can change the settings here
//
>>
//
fadeTimerFreq is the clock speed in milliseconds, lower numbers are faster
const int fadeTimerFreq = 30;
//
fadeTime is the total time it will take to complete the ease (in milliseconds)
const int fadeTime = 3000;
//
<<
//
additional variable for the timer
int currentTime, fadeTimerLast;
//
these constant variables store the pin numbers
const int ledPin = 9;
const int buttonPin = 8;
const int fadeRange = 254;
//
the amount to step the fade; must be between 1 and the fadeRange
const float fadeStep = (float(fadeTimerFreq) / (fadeTime)) * fadeRange;
int buttonValue, fadeTarget, fadeValueTweened;
float fadeValue;
void setup() {