Menu mobile
En esta lección, realizaremos un experimento simple pero interesante: usar LED para crear luces LED que fluyan. Como su nombre lo indica, estas luces que fluyen están formadas por ocho LED en una fila que se iluminan sucesivamente y se atenúan una tras otra como el agua que fluye.
{Product:2000}{Product:1436}{Product:287}{Product:603}{Product:13}
El principio de este experimento es simplemente encender ocho LED del modo descrito en la introducción.
Paso 1: conecta el circuito como se muestra en el siguiente diagrama.
El diagrama esquemático correspondiente es el siguiente:
Paso 2: Programa (consulta el código de ejemplo en el CD o en la web oficial)
/* Eight LEDs will light up one by one from left to right, and then go out one by one from right to left.
After that, the LEDs will light up one by one from right to left, and then go out one by one from left to right.
This process will repeat indefinitely.*/
//Email:[email protected]
//Website:www.sunfounder.com
//2015.5.7
/**************************************/
const int lowestPin = 2;//the lowest one attach to pin 2
const int highestPin = 9;//the highest one attach to pin 9
void setup()
{
//set pins 2 through 9 as output
for(int thisPin = lowestPin;thisPin <= highestPin;thisPin++)
pinMode(thisPin,OUTPUT); //initialize thisPin as an output
}
/****************************************/
void loop()
//iterate over the pins
//turn the led on from lowest to the highest
digitalWrite(thisPin,HIGH);//turn this led on
delay(100);//wait for 100 ms
//fade from the highest to the lowest
for(int thisPin = highestPin;thisPin>=lowestPin;thisPin--)
digitalWrite(thisPin,LOW);//turn this led off
} )
Paso 3: Compila el programa
Paso 4: Graba el programa en la placa Uno
Aquí deberías ver que ocho LEDs se iluminan uno por uno de izquierda a derecha y se apagan uno por uno de derecha a izquierda. Este proceso se repetirá ininterrumpidamente.
Este sencillo experimento ayuda a aumentar la competencia en la aplicación de los LEDs. Además, puedes modificar el programa proporcionado para crear todo tipo de patrones fantásticos.