Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. const int MAXLED = 8;
  2. //Pin connected to ST_CP of 74HC595 --- pin 12
  3. int latchPin = 8;
  4. //Pin connected to SH_CP of 74HC595 -- pin 11
  5. int clockPin = 12;
  6. ////Pin connected to DS of 74HC595  --pin 14
  7. int dataPin = 11;
  8. //se asigna a una variable el puerto análogo del arduino
  9. int pot = A4;
  10. // se guarda la lectura del potenciometro
  11. int valpot =0;
  12.  
  13. // arreglo de 8 LEDs
  14. int led[MAXLED] = {1,2,4,8,16,32,64,128};
  15.  
  16. //primera secuencia : arreglo de un led de por medio
  17. int ledS1[14] = {1,2,4,8,4,2,1,16,32,64,128,64,32,16};
  18.  
  19.  
  20. //segunda secuencia : arreglo de un leds de los extremos al medio
  21. int ledS2[MAXLED] = {2,4,8,16,128,64,32,16};
  22.  
  23.  
  24. //tercera secuencia
  25. int ledS3[MAXLED] = {1,4,16,64,2,8,32,128};
  26.  
  27. //cuarta secuencia
  28. int ledS4[MAXLED] = {2,4,128,64,8,16,32,1};
  29.  
  30.  
  31.  
  32.  
  33. // se ejecuta 1 sola vez, al iniciar el programa
  34. void setup() {
  35.   //set pins to output so you can control the shift register
  36.   pinMode(latchPin, OUTPUT);
  37.   pinMode(clockPin, OUTPUT);
  38.   pinMode(dataPin, OUTPUT);
  39.   pinMode(pot, INPUT);
  40. }
  41.  
  42.  
  43.  
  44.  
  45. // se repite infinitamente mientras el arduino tenga corriente
  46. void loop() {
  47. // recorre desde el indice 0 hasta el 7  
  48. for (int i=0; i<MAXLED; i++) {
  49.  
  50.      digitalWrite(latchPin, LOW);
  51.     delay(100);
  52.     // shift out the bits:
  53.     shiftOut(dataPin, clockPin, MSBFIRST,led[i]);
  54.     //take the latch pin high so the LEDs will light up:
  55.     digitalWrite(latchPin, HIGH);
  56.     // pause before next value:
  57.     delay(100);
  58.  
  59.          
  60.        
  61.         //se hace una lectura del potenciometro
  62.           valpot = analogRead(pot);
  63.         //se evalua,  dependiendo del valor del potenciometro
  64.         // se le asigna una secuencia  
  65.           if( valpot > 0  && valpot <256)
  66.           { secuenciaUno(); }      
  67.           else if(valpot > 256  && valpot < 512)
  68.           {  secuenciaDos();}
  69.           else if(valpot > 512  && valpot < 768)
  70.           {  secuenciaTres();}
  71.          else if(valpot > 768  && valpot < 1024)
  72.          {  secuenciaCuatro();}
  73.          
  74.  }
  75.  
  76.  // recorre desde el indice 6 hasta el 1, para no repetir los extremos
  77.  for (int i=MAXLED-2; i>0; i--) {
  78.     // take the latchPin low so
  79.     // the LEDs don't change while you're sending in bits:
  80.     digitalWrite(latchPin, LOW);
  81.     delay(100);
  82.     // shift out the bits:
  83.     shiftOut(dataPin, clockPin, MSBFIRST,led[i]);
  84.  
  85.     //take the latch pin high so the LEDs will light up:
  86.     digitalWrite(latchPin, HIGH);
  87.     // pause before next value:
  88.     delay(100);
  89.   }
  90.  
  91.  
  92.  
  93. }
  94. void secuenciaUno(){
  95.    uno:
  96.   //recorre el arreglo donde se difinio la secuencia
  97.    for (int i=0; i<14; i++){
  98.      
  99.      // take the latchPin low so
  100.   // the LEDs don't change while you're sending in bits:
  101.   digitalWrite(latchPin, LOW);
  102.   delay(500);
  103.   // shift out the bits:
  104.   shiftOut(dataPin, clockPin, MSBFIRST, ledS1[i]);  
  105.   //take the latch pin high so the LEDs will light up:
  106.   digitalWrite(latchPin, HIGH);
  107.   delay(700);  
  108.   }  
  109.  
  110.      //se hace una lectura previa para saber
  111.      //si todavia se esta ejecutando la secuencia actual
  112.      valpot = analogRead(pot);
  113.      if( valpot > 0  && valpot <256){  
  114.      goto uno; }        
  115. }
  116.  
  117.  
  118.  
  119. //secuencia II
  120. void secuenciaDos(){  
  121.    
  122.    
  123.  
  124.   dos:  
  125.  //recorro ciclo de los leds
  126.  for (int i=0; i<MAXLED; i++){              
  127.  
  128.    
  129.    // take the latchPin low so
  130.   // the LEDs don't change while you're sending in bits:
  131.   digitalWrite(latchPin, LOW);
  132.   delay(100);
  133.   // shift out the bits:
  134.   shiftOut(dataPin, clockPin, MSBFIRST, ledS2[i]);  
  135.   //take the latch pin high so the LEDs will light up:    
  136.    digitalWrite(latchPin, HIGH);
  137.    delay(250);      
  138. }
  139.  
  140.     //se hace una lectura previa para saber
  141.      //si todavia se esta ejecutando la secuencia actual                        
  142.     valpot = analogRead(pot);
  143.     if(valpot > 256   && valpot < 512){    
  144.     goto dos; }
  145.  
  146. }
  147. //Metodo de secuencia III
  148. void secuenciaTres(){
  149. tres:
  150. //recorre el arreglo donde se difinio la secuencia
  151. for (int i=0; i<MAXLED; i++) {
  152.  
  153.  
  154.    // take the latchPin low so
  155.   // the LEDs don't change while you're sending in bits:
  156.   digitalWrite(latchPin, LOW);
  157.   delay(100);
  158.   // shift out the bits:
  159.   shiftOut(dataPin, clockPin, MSBFIRST, ledS3[i]);  
  160.   //take the latch pin high so the LEDs will light up:
  161.   digitalWrite(latchPin, HIGH);
  162.   delay(700);  
  163.          
  164. }
  165.     //se hace una lectura previa para saber
  166.      //si todavia se esta ejecutando la secuencia actual
  167.     valpot = analogRead(pot);
  168.     if(valpot > 512  && valpot < 768){    
  169.     goto tres; }
  170. }
  171.  
  172. //secuencia IV
  173. void secuenciaCuatro(){
  174.  //var definir la posicion de los ultimos 4 leds
  175.    int num = 0;
  176.  
  177.  cuatro:
  178. //recorre el arreglo donde se difinio la secuencia
  179. for (int i=0; i<MAXLED; i++) {
  180.            
  181.            
  182.            
  183.              // take the latchPin low so
  184.   // the LEDs don't change while you're sending in bits:
  185.   digitalWrite(latchPin, LOW);
  186.   delay(100);
  187.   // shift out the bits:
  188.   shiftOut(dataPin, clockPin, MSBFIRST, ledS4[i]);  
  189.   //take the latch pin high so the LEDs will light up:
  190.   digitalWrite(latchPin, HIGH);
  191.   delay(250);  
  192. }
  193.     //se hace una lectura previa para saber
  194.      //si todavia se esta ejecutando la secuencia actual
  195.     valpot = analogRead(pot);
  196.     if(valpot > 768  && valpot < 1024){    
  197.     goto cuatro; }
  198. }