//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
//se declara una variable de tipo char para obtener que slider se esta usando en el proccesing
char res;
//variables donde se guardan el valor que indica cada slide
int encendido=128, apagado=128;
const int MAXLED = 8;
// arreglo de 8 LEDs, desde el pin 2 hasta el pin 9
int led[MAXLED] = {1,2,4,8,16,32,64,128};
void setup() {
//configuracion de pines de salida
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
for (int i=0; i<MAXLED; i++)
pinMode(led[i], OUTPUT);
Serial.begin(9600);
}
void loop() {
for (int i=0; i<MAXLED; i++) {
leerDatos();
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
delay(apagado);
// 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(encendido);
}
for (int i=MAXLED-2; i>0; i--) {
leerDatos();
// El LED no cambian mientras se está enviando en bits
digitalWrite(latchPin, LOW);
delay(apagado);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST,led[i]);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// Hacer una pausa antes de el siguiente valor
delay(encendido);
}
}
void leerDatos(){
if (Serial.available()>0) {
res=Serial.read();
if (res=='e') {
encendido = Serial.read();
}
else if (res=='a') {
apagado = Serial.read();
}
}
}