Created
September 14, 2009 09:31
-
-
Save alx/186575 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
El Cumpleaños de Mercedes | |
-- Mirar y Leer -- | |
Aqui solo se lee la luz. | |
Despues de ver lo que he escrito el año pasado, no tengo mas tonterias a escribir en el papel. | |
-- Abrir y Juegar -- | |
El program esta muy simple, todo el mundo puede cambiarlo. | |
Las leds estan numerotadas de 0 a 9 (binary world). | |
-- Datos -- | |
Fecha: 24/09/2009 | |
Codigo: Alexandre Girard - alx.girard@gmail.com | |
Internals: Lionel - liodel@gmail.com | |
*/ | |
// Conneccion de los leds al arduino | |
int ledPin[10]; | |
// Counters para juegar cada programa | |
// durante el pulso | |
byte digital_sequence[50]; | |
int digital_counter[50]; | |
int current_sequence; | |
int current_counter; | |
void setup() | |
{ | |
// Level encima, en PWM | |
ledPin[0] = 9; | |
ledPin[1] = 10; | |
ledPin[2] = 11; | |
// Level en la mitad | |
ledPin[3] = 8; | |
ledPin[4] = 7; | |
ledPin[5] = 6; | |
ledPin[6] = 5; | |
// Level bajo | |
ledPin[7] = 4; | |
ledPin[8] = 3; | |
ledPin[9] = 2; | |
// Connectas los leds a los pin en OUTPUT | |
for (int pin = 0; pin < 10; pin++) { | |
pinMode(ledPin[pin], OUTPUT); | |
} | |
// Switch on top leds | |
for(int value = 0 ; value <= 5; value+=1) | |
{ | |
analogWrite(ledPin[0], value); | |
analogWrite(ledPin[1], value); | |
analogWrite(ledPin[2], value); | |
delay(30); | |
} | |
} | |
// Loop principal | |
void loop() | |
{ | |
change_sequence(); | |
pulso(10); | |
} | |
// Al fin de cada loop | |
// cambia el programa de los leds | |
void change_sequence() { | |
sequence_random(); | |
current_sequence = 0; | |
current_counter = 0; | |
} | |
// Controla los leds de encima | |
void pulso(int number_of_loop) | |
{ | |
for(int i = 0; i < number_of_loop; i++) { | |
for(int value = 15; value <= 255; value+=10) | |
{ | |
analogWrite(ledPin[0], value); | |
analogWrite(ledPin[1], value); | |
analogWrite(ledPin[2], value); | |
delay(25); | |
call_sequence(); | |
} | |
for(int value = 255; value >=15; value-=10) | |
{ | |
analogWrite(ledPin[0], value); | |
analogWrite(ledPin[1], value); | |
analogWrite(ledPin[2], value); | |
delay(25); | |
call_sequence(); | |
} | |
} | |
} | |
// Durante el pulso, controla las otras LEDs | |
void call_sequence(){ | |
if(digital_counter[current_sequence] == current_counter) { | |
// Fin de sequencia, vuelve al principio | |
if(digital_sequence[current_sequence] == B00000000) { | |
current_sequence = 0; | |
} | |
light_byte(digital_sequence[current_sequence]); | |
current_sequence++; | |
} | |
current_counter++; | |
} | |
// Programa Sequence_Random | |
void sequence_random() { | |
for(int i = 0; i < 49; i++) { | |
digital_sequence[i] = byte(random(1, 255)); | |
digital_counter[i] = int(random(10, 50)) + digital_counter[i - 1]; | |
} | |
digital_sequence[49] = B00000000; | |
} | |
// Enciende todas la LEDs connectadas a los pin digital (no PWM) | |
void digital_on(int millisec) { | |
byte b = B11111111; | |
light_byte(b); | |
delay(millisec); | |
} | |
// Apaga todas la LEDs connectadas a los pin digital (no PWM) | |
void digital_off(int millisec) { | |
byte b = B00000000; | |
light_byte(b); | |
delay(millisec); | |
} | |
// Enciende los LEDs usando bytes | |
// | |
// Formato de numeros: | |
// {9, 8, 7, 6, 5, 4, 3, nil} | |
void light_byte(byte pattern) { | |
for (int i = 0; i < 8; i++, pattern >>= 1) { | |
digitalWrite(ledPin[i + 3], pattern & 1 ? HIGH : LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment