En este laboratorio controlamos 8 LEDs desde el arduino, a través de un IC 74HC595, definiendo mínimo 8 patrones de movimiento que son controlados desde un Potenciometro.
Implemento
Diagrama del montaje en la protoboard
Diagrama esquemático del circuito
Fotos del montaje
Vídeo del funcionamiento
Código fuente en arduino
#define PIN 3
#define Pot A0
const int Latch = 10;
const int Clock = 11;
const int Data = 9;
int led[PIN] = {
9,10,11};
int Serie1[5]={66,36,24,24,36,};
int Serie2[9]={0,128,192,224,240,248,252,254,255};
int Serie3[12]={255,126,60,24,16,8,16,8,24,60,126,255};
int Serie4[10]={240,15,8,3,2};
int Serie5[14]={129,0,131,133,137,145,161,0,193,161,145,137,133,131};
int Serie6[6]={195,60,44,22,11,6};
int Serie7[11]={1,0,1,0,15,0,15,0,255,255,0};
int Serie8[25]={1,2,4,8,16,32,64,128,64,32,16,8,4,2,1,2,4,8,16,32,64,128,192,160,0};
void setup() {
for (int i=0; i<PIN; i++){
pinMode(led[i], OUTPUT);
}
pinMode(Pot, INPUT);
}
void loop()
{
int Pos = analogRead(Pot);
Pos = map(Pos, 0, 1023, 0,7);
Casos(Pos);
}
void Casos(int Valor)
{
switch(Valor)
{
case 0:
for(int j=0;j<7;j++)
{
On(Serie1[j]);
}
break;
case 1:
for(int j=0;j<9;j++)
{
On(Serie2[j]);
}
break;
case 2:
for(int j=0;j<12;j++)
{
On(Serie3[j]);
}
break;
case 3:
for(int j=0;j<10;j++)
{
On(Serie4[j]);
}
break;
case 4:
for(int j=0;j<14;j++)
{
On(Serie5[j]);
}
break;
case 5:
for(int j=0;j<6;j++)
{
On(Serie6[j]);
}
break;
case 6:
for(int j=0;j<11;j++)
{
On(Serie7[j]);
}
break;
case 7:
for(int j=0;j<50;j++)
{
On(Serie8[j]);
}
break;
}
}
void On(int Valor)
{
digitalWrite(Latch, LOW);
shiftOut(Data, Clock, MSBFIRST, Valor);
digitalWrite(Latch, HIGH);
delay(100);
}
No hay comentarios:
Publicar un comentario