Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int MAXLED = 8;
- //Pin connected to ST_CP of 74HC595 --- pin 12
- int latchPin = 8;
- //Pin connected to SH_CP of 74HC595 -- pin 11
- int clockPin = 12;
- ////Pin connected to DS of 74HC595 --pin 14
- int dataPin = 11;
- //se asigna a una variable el puerto análogo del arduino
- int pot = A4;
- // se guarda la lectura del potenciometro
- int valpot =0;
- // arreglo de 8 LEDs
- int led[MAXLED] = {1,2,4,8,16,32,64,128};
- //primera secuencia : arreglo de un led de por medio
- int ledS1[14] = {1,2,4,8,4,2,1,16,32,64,128,64,32,16};
- //segunda secuencia : arreglo de un leds de los extremos al medio
- int ledS2[MAXLED] = {2,4,8,16,128,64,32,16};
- //tercera secuencia
- int ledS3[MAXLED] = {1,4,16,64,2,8,32,128};
- //cuarta secuencia
- int ledS4[MAXLED] = {2,4,128,64,8,16,32,1};
- // se ejecuta 1 sola vez, al iniciar el programa
- void setup() {
- //set pins to output so you can control the shift register
- pinMode(latchPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- pinMode(pot, INPUT);
- }
- // se repite infinitamente mientras el arduino tenga corriente
- void loop() {
- // recorre desde el indice 0 hasta el 7
- for (int i=0; i<MAXLED; i++) {
- digitalWrite(latchPin, LOW);
- delay(100);
- // shift out the bits:
- shiftOut(dataPin, clockPin, MSBFIRST,led[i]);
- //take the latch pin high so the LEDs will light up:
- digitalWrite(latchPin, HIGH);
- // pause before next value:
- delay(100);
- //se hace una lectura del potenciometro
- valpot = analogRead(pot);
- //se evalua, dependiendo del valor del potenciometro
- // se le asigna una secuencia
- if( valpot > 0 && valpot <256)
- { secuenciaUno(); }
- else if(valpot > 256 && valpot < 512)
- { secuenciaDos();}
- else if(valpot > 512 && valpot < 768)
- { secuenciaTres();}
- else if(valpot > 768 && valpot < 1024)
- { secuenciaCuatro();}
- }
- // recorre desde el indice 6 hasta el 1, para no repetir los extremos
- for (int i=MAXLED-2; i>0; i--) {
- // take the latchPin low so
- // the LEDs don't change while you're sending in bits:
- digitalWrite(latchPin, LOW);
- delay(100);
- // shift out the bits:
- shiftOut(dataPin, clockPin, MSBFIRST,led[i]);
- //take the latch pin high so the LEDs will light up:
- digitalWrite(latchPin, HIGH);
- // pause before next value:
- delay(100);
- }
- }
- void secuenciaUno(){
- uno:
- //recorre el arreglo donde se difinio la secuencia
- for (int i=0; i<14; i++){
- // take the latchPin low so
- // the LEDs don't change while you're sending in bits:
- digitalWrite(latchPin, LOW);
- delay(500);
- // shift out the bits:
- shiftOut(dataPin, clockPin, MSBFIRST, ledS1[i]);
- //take the latch pin high so the LEDs will light up:
- digitalWrite(latchPin, HIGH);
- delay(700);
- }
- //se hace una lectura previa para saber
- //si todavia se esta ejecutando la secuencia actual
- valpot = analogRead(pot);
- if( valpot > 0 && valpot <256){
- goto uno; }
- }
- //secuencia II
- void secuenciaDos(){
- dos:
- //recorro ciclo de los leds
- for (int i=0; i<MAXLED; i++){
- // take the latchPin low so
- // the LEDs don't change while you're sending in bits:
- digitalWrite(latchPin, LOW);
- delay(100);
- // shift out the bits:
- shiftOut(dataPin, clockPin, MSBFIRST, ledS2[i]);
- //take the latch pin high so the LEDs will light up:
- digitalWrite(latchPin, HIGH);
- delay(250);
- }
- //se hace una lectura previa para saber
- //si todavia se esta ejecutando la secuencia actual
- valpot = analogRead(pot);
- if(valpot > 256 && valpot < 512){
- goto dos; }
- }
- //Metodo de secuencia III
- void secuenciaTres(){
- tres:
- //recorre el arreglo donde se difinio la secuencia
- for (int i=0; i<MAXLED; i++) {
- // take the latchPin low so
- // the LEDs don't change while you're sending in bits:
- digitalWrite(latchPin, LOW);
- delay(100);
- // shift out the bits:
- shiftOut(dataPin, clockPin, MSBFIRST, ledS3[i]);
- //take the latch pin high so the LEDs will light up:
- digitalWrite(latchPin, HIGH);
- delay(700);
- }
- //se hace una lectura previa para saber
- //si todavia se esta ejecutando la secuencia actual
- valpot = analogRead(pot);
- if(valpot > 512 && valpot < 768){
- goto tres; }
- }
- //secuencia IV
- void secuenciaCuatro(){
- //var definir la posicion de los ultimos 4 leds
- int num = 0;
- cuatro:
- //recorre el arreglo donde se difinio la secuencia
- for (int i=0; i<MAXLED; i++) {
- // take the latchPin low so
- // the LEDs don't change while you're sending in bits:
- digitalWrite(latchPin, LOW);
- delay(100);
- // shift out the bits:
- shiftOut(dataPin, clockPin, MSBFIRST, ledS4[i]);
- //take the latch pin high so the LEDs will light up:
- digitalWrite(latchPin, HIGH);
- delay(250);
- }
- //se hace una lectura previa para saber
- //si todavia se esta ejecutando la secuencia actual
- valpot = analogRead(pot);
- if(valpot > 768 && valpot < 1024){
- goto cuatro; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement