Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Arquitectura de Computadoras
Uso de leds
Usa leds de salida en los pines D10 a D13, como se muestra en el grafico siguiente:
Codigo de Ejemplo:
void setup()
pinMode(i, OUTPUT);
void loop()
{
digitalWrite(i, LOW);
delay(200);
digitalWrite(i, HIGH);
delay(200);
8 Multiple LEDs
Se han usado un programa que hace que un LED parpadee, ahora es el momento de los
bloques. Permite conectar ocho. Vamos a tener una oportunidad para extender el uso de
Arduino mediante la creación de diversas secuencias de iluminación. Este circuito es
también una buena configuración para experimentar con la escritura de sus propios
programas y obtener una idea de cómo funciona el Arduino.
Junto con el control de los LEDs se va a empezar a buscar métodos de programación
simples para mantener a los programas.
for() loops - used when you want to run a piece of code several times.
arrays[] - used to make managing variables easier (it's a group of variables).
Materiales
5mm Yellow LED x8
8 x 330 Ohm Resistores 8O en su defecto 220 ohms
Cables para protoboard
Diagrama esquemático
El código a ingresar será:
/* ---------------------------------------------------------
int ledPins[] = {2,3,4,5,6,7,8,9}; //An array to hold the pin each LED is
connected to
/*
* setup() - this function runs once when you turn your Arduino on
*/
void setup()
//Set each pin connected to an LED to output mode (pulling high (on) or low
(off)
for(int i = 0; i < 8; i++){ //this is a loop and will repeat eight times
pinMode(ledPins[0],OUTPUT);
pinMode(ledPins[1],OUTPUT);
pinMode(ledPins[2],OUTPUT);
pinMode(ledPins[3],OUTPUT);
pinMode(ledPins[4],OUTPUT);
pinMode(ledPins[5],OUTPUT);
pinMode(ledPins[6],OUTPUT);
pinMode(ledPins[7],OUTPUT);
/*
* loop() - this function will start after setup finishes and then repeat
*/
{
oneAfterAnotherNoLoop(); //this will turn on each LED one by one then
turn each off
//oneOnAtATime(); //this will turn one LED on then turn the next one
//inAndOut(); //lights the two middle LEDs then moves them out
then back
//in again
/*
* the next LED until all LEDs are on it will then turn them off one after
another
* this does it without using a loop which makes for a lot of typing.
*/
void oneAfterAnotherNoLoop(){
int delayTime = 100; //the time (in milliseconds) to pause between LEDs
/*
* oneAfterAnotherLoop() - Will light one LED then delay for delayTime then
light
* the next LED until all LEDs are on it will then turn them off one after
another
* this does it using a loop which makes for a lot less typing.
* than oneOnAtATimeNoLoop() does exactly the same thing with less typing
*/
void oneAfterAnotherLoop(){
int delayTime = 100; //the time (in milliseconds) to pause between LEDs
for(int i = 7; i >= 0; i--){ //same as above but rather than starting at 0 and
counting up
/*
* oneOnAtATime() - Will light one LED then the next turning off all the others
*/
void oneOnAtATime(){
int delayTime = 100; //the time (in milliseconds) to pause between LEDs
int offLED = i - 1; //Calculate which LED was turned on last time through
delay(delayTime);
}
/*
* inAndOut() - This will turn on the two middle LEDs then the next two out
*/
void inAndOut(){
int delayTime = 100; //the time (in milliseconds) to pause between LEDs
int offLED = i - 1; //Calculate which LED was turned on last time through
//#0 when i = 3
//#7 when i = 3
int offLED1 = 3 - offLED; //turns off the LED we turned on last time
int offLED2 = 4 + offLED; //turns off the LED we turned on last time
digitalWrite(ledPins[onLED1], HIGH);
digitalWrite(ledPins[onLED2], HIGH);
digitalWrite(ledPins[offLED1], LOW);
digitalWrite(ledPins[offLED2], LOW);
delay(delayTime);
int offLED = i + 1; //Calculate which LED was turned on last time through
//#0 when i = 3
//#7 when i = 3
int offLED1 = 3 - offLED; //turns off the LED we turned on last time
int offLED2 = 4 + offLED; //turns off the LED we turned on last time
digitalWrite(ledPins[onLED1], HIGH);
digitalWrite(ledPins[onLED2], HIGH);
digitalWrite(ledPins[offLED1], LOW);
digitalWrite(ledPins[offLED2], LOW);
delay(delayTime);
char* letras[] = {
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", // A-I
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", // J-R
};
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
void loop()
char ch;
flashSequence(letras[ch - 'a']);
flashSequence(letras[ch - 'A']);
{
flashSequence(numeros[ch - '0']);
int i = 0;
flashDotOrDash(secuencia[i]);
i++;
digitalWrite(ledPin, HIGH);
if (dotOrDash == '.') {
delay(dotDelay);
delay(dotDelay * 3);
digitalWrite(ledPin, LOW);