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. // variable tipo char para obtener que slide se esta usando en el proccesing
  8. char res;
  9. //variables donde se guardan el valor que indica cada slide
  10. int encendido=128, apagado=128;
  11. const int MAXLED = 8;
  12. // arreglo de 8 LEDs, desde el pin 2 hasta el pin 9
  13. int led[MAXLED] = {1,2,4,8,16,32,64,128};
  14.  
  15.  
  16. void setup() {
  17. //set pins to output so you can control the shift register
  18. pinMode(latchPin, OUTPUT);
  19. pinMode(clockPin, OUTPUT);
  20. pinMode(dataPin, OUTPUT);
  21. for (int i=0; i<MAXLED; i++)
  22. pinMode(led[i], OUTPUT);
  23. Serial.begin(9600);
  24. }
  25.  
  26. void loop() {
  27. // count from 0 to 255 and display the number
  28. // on the LEDs
  29.  
  30. for (int i=0; i<MAXLED; i++) {
  31. leerDatos();
  32. // take the latchPin low so
  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. // take the latchPin low so
  50. // the LEDs don't change while you're sending in 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. // pause before next value:
  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. }