int clockPinLed = 8; //Pin del reloj del "shift registrer" para los LED
int latchPinLed = 9; //Pin del pestillo del "shift registrer" para los LED
int dataPinLed = 10; //Pin de datos del "shift registrer" para los LED
byte myByteLed = 0b00000000; //Variable para los bits de los LED
int clockPinDisplay = 11; //Pin del reloj del "shift registrer" para el Display
int latchPinDisplay = 12; //Pin del pestillo del "shift registrer" para el Display
int dataPinDisplay = 13; //Pin de datos del "shift registrer" para el Display
byte myByteDisplay = 0b00000000; //Variable para los bits del Display
int n; //Variable que nos servira de contador
int bits[] = { //Array con los bits necesarios para la secuencia
1, 2, 4, 8, 16, 32, 64, 128,
129, 130, 132, 136, 144, 160, 192,
193, 194, 196, 200, 208, 224,
225, 226, 228, 232, 240,
241, 242, 244, 248,
249, 250, 252,
253, 254
};
int numbers[] = { //Array con los bits necesarios para crear los numeros del display
0b00111111,
0b00000110,
0b01011011,
0b01001111,
0b01100110,
0b01101101,
0b01111101,
0b00000111,
0b01111111,
};
void setup() {
// put your setup code here, to run once:
//Se inician los pines del "Shift registrer" de los LED
pinMode(clockPinLed, OUTPUT);
pinMode(latchPinLed, OUTPUT);
pinMode(dataPinLed, OUTPUT);
//Se inician los pines del "Shift registrer" del Display
pinMode(clockPinDisplay, OUTPUT);
pinMode(latchPinDisplay, OUTPUT);
pinMode(dataPinDisplay, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//Se apagan los pestillos de ambos "Shift registrer" para que recojan los datos
digitalWrite(latchPinLed, 0);
digitalWrite(latchPinDisplay, 0);
//Condicionales encargadas de que funcione la secuancia de numeros del Display y los sonidos
if (myByteLed < 128) {
myByteDisplay = numbers[0];
}
else if (myByteLed == 128) {
myByteDisplay = numbers[1];
tone(7, 500, 8);
}
else if (myByteLed == 160) {
myByteDisplay = numbers[2];
tone(7, 525, 8);
}
else if (myByteLed == 208) {
myByteDisplay = numbers[3];
tone(7, 550, 8);
}
else if (myByteLed == 232) {
myByteDisplay = numbers[4];
tone(7, 575, 8);
}
else if (myByteLed == 244) {
myByteDisplay = numbers[5];
tone(7, 600, 8);
}
else if (myByteLed == 250) {
myByteDisplay = numbers[6];
tone(7, 625, 8);
}
else if (myByteLed == 253) {
myByteDisplay = numbers[7];
tone(7, 650, 8);
}
else if (myByteLed == 254) {
myByteDisplay = numbers[8];
}
//Cuando la secuencia de LEDs se complete se emitira un sonido mas grave y extenso
if (myByteLed == 254) {
n = 0;
tone(7, 400, 100);
}
//Hara que se muestre en los LEDs el byte que tenga el indice guardado en la variable contador 'n'
myByteLed = bits[n];
//Se inician ambos "Shift registrer" pasando como parametros el pin de datos, el pin del reloj, el dato mas significativo y la variable que contiene el byte
shiftOut(dataPinLed, clockPinLed, MSBFIRST, myByteLed);
shiftOut(dataPinDisplay, clockPinDisplay, MSBFIRST, myByteDisplay);
//Se encienden ambos pestillos
digitalWrite(latchPinLed, 1);
digitalWrite(latchPinDisplay, 1);
n++; //Al terminar cada vuelta de bulce la variable 'n' aumenta su valor en 1
delay(150); //Tiempo de espera de 150 milisegundos
}