//Definimos los pines de nuestro registro
# define latch_pin 9
# define data_pin 8
# define clock_pin 10
//Configuramos los pines como salidas
void setup ()
{
for (int n=8; n<11; n++)
{
pinMode(n,OUTPUT);
}
void loop ()
{
//Bucle para activar la secuencia
for(int sec=0; sec<8;sec++)
{
digitalWrite(latch_pin,HIGH);
shiftOut(data_pin,clock_pin, MSBFIRST, animacion(sec) );
delay(50);
digitalWrite(latch_pin,LOW);
}
}
//La función devuelve un numero binario que se corresponde con nuestra
//animación en cada momento de la secuencia
int animacion (int sec_ )
{
int frame =0;
switch(sec_)
{
case 0:
frame = B00000001;
break;
case 1:
frame = B00000010;
break;
case 2:
frame = B01000000;
break;
case 3:
frame = B00010000;
break;
case 4:
frame = B00001000;
break;
case 5:
frame = B00000100;
break;
case 6: frame = B01000000;
break;
case 7: frame = B00100000;
break;
}
return frame;
}