//REGISTRO DE DESPLAZAMIENTO
int Data = 2; //Pin 14 del 74hc595
int Latch = 3; //Pin 12 del 74hc595
int Clock = 4; //Pin 11 del 74hc595
//DISPLAYS
int hor1 = 0;
int hor2 = 0;
int min1 = 0;
int min2 = 0;
int seg1 = 0;
int seg2 = 0;
//RESTABLECIMIENTO DE DISPLAYS
int hora = 18;
int segundos = 54;
int minutos = 59;
// ARREGLO PARA LOS NUMEROS EN DISPLAYS CATODO COMÚN
const byte S[] = {0, 252, 96, 218, 242, 102, 182, 190, 224, 254, 230,};
void HC595(int cont1, int cont2, int cont3, int cont4, int cont5, int cont6)
{
shiftOut(Data, Clock, LSBFIRST, cont2);
shiftOut(Data, Clock, LSBFIRST, cont1);
shiftOut(Data, Clock, LSBFIRST, cont3);
shiftOut(Data, Clock, LSBFIRST, cont4);
shiftOut(Data, Clock, LSBFIRST, cont6);
shiftOut(Data, Clock, LSBFIRST, cont5);
digitalWrite(Latch, HIGH);
digitalWrite(Latch, LOW);
}
//FUNCIÓN PARA ESCRIBIR UN NUMERO
void num(int a, int b, int c, int d, int e, int f) {
HC595(S[a + 1], S[b + 1], S[c + 1], S[d + 1], S[e + 1], S[f + 1]);
}
void setup() {
pinMode(Data, OUTPUT);
pinMode(Latch, OUTPUT);
pinMode(Clock, OUTPUT);
pinMode(5, OUTPUT);
}
void loop() {
// CONDICIONES
if(minutos == 59 && hora < 23 && segundos == 59){
hora ++;
minutos = 0;
segundos =0;
}
if(hora == 60 && hora >= 23 && segundos ==60){
hora = 0;
minutos = 0;
segundos= 0;
}
delay(200);
//INCREMENTOS
if (segundos<60){
segundos++;
}
if (segundos >= 60) {
segundos = 0;
minutos++;
}
if(minutos == 60 && hora < 23){
hora ++;
minutos = 0;
}
if(minutos == 60 && hora >= 23){
hora = 0;
minutos = 0;
}
// SEPARACIÓN DE DIGITOS EN LOS 7 SEGMENTOS
hor1 = hora / 10;
hor2 = hora % 10;
min1 = minutos / 10;
min2 = minutos % 10;
seg1= segundos / 10;
seg2 = segundos % 10;
num(seg1,seg2,min2,min1,hor1,hor2); //IMPRESIÓN
// SECUENCIA DE LEDS
digitalWrite(5, HIGH);
delay(500);
digitalWrite(5, LOW);
delay(500);
}