Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //Pin connected to ST_CP of 74HC595
  2. int latchPin = 8;
  3. //Pin connected to SH_CP of 74HC595
  4. int clockPin = 12;
  5. ////Pin connected to DS of 74HC595
  6. int dataPin = 11;
  7. //se declara una variable de tipo char para obtener que slider se esta usando en el proccesing
  8. char res;
  9.  
  10. //variables donde se guardan el valor que indica cada slide
  11. int encendido=128, apagado=128;
  12. const int MAXLED = 8;
  13. // arreglo de 8 LEDs, desde el pin 2 hasta el pin 9
  14. int led[MAXLED] = {1,2,4,8,16,32,64,128};
  15.  
  16.  
  17. void setup() {
  18.   //configuracion de pines de salida
  19.   pinMode(latchPin, OUTPUT);
  20.   pinMode(clockPin, OUTPUT);
  21.   pinMode(dataPin, OUTPUT);
  22.    for (int i=0; i<MAXLED; i++)
  23.    pinMode(led[i], OUTPUT);
  24.    Serial.begin(9600);
  25. }
  26.  
  27. void loop() {
  28.  
  29.  
  30.  for (int i=0; i<MAXLED; i++) {
  31.     leerDatos();
  32.  
  33.     // the LEDs don't change while you're sending in bits:
  34.     digitalWrite(latchPin, LOW);
  35.     delay(apagado);
  36.    
  37.    
  38.     // shift out the bits:
  39.     shiftOut(dataPin, clockPin, MSBFIRST,led[i]);
  40.  
  41.     //take the latch pin high so the LEDs will light up:
  42.     digitalWrite(latchPin, HIGH);
  43.     // pause before next value:
  44.     delay(encendido);
  45.  }
  46.  
  47.  for (int i=MAXLED-2; i>0; i--) {
  48.    leerDatos();
  49.    
  50.     // El LED no cambian mientras se está enviando en bits
  51.     digitalWrite(latchPin, LOW);
  52.     delay(apagado);
  53.     // shift out the bits:
  54.     shiftOut(dataPin, clockPin, MSBFIRST,led[i]);
  55.  
  56.     //take the latch pin high so the LEDs will light up:
  57.     digitalWrite(latchPin, HIGH);
  58.     // Hacer una pausa antes de el siguiente valor
  59.     delay(encendido);
  60.  }
  61.  
  62. }
  63.  
  64.  void leerDatos(){
  65.   if (Serial.available()>0) {
  66.     res=Serial.read();
  67.     if (res=='e') {
  68.       encendido = Serial.read();
  69.     }
  70.     else if (res=='a') {
  71.       apagado = Serial.read();
  72.     }
  73.    
  74.   }
  75. }