dado bb

Con esta sencilla aplicación se pueden revisar conceptos básicos de Arduino
 
 

Componentes

2 Resistencias de 1k

1 Resistencia 100 ohms

1 Arduino Uno

1 Display 8  Segmentos LTS367R

1 Protoboard

1 Pulsador


Para las conexiones en el display usamos la siguiente convención:

 

tabla

display

 

Una vez hecho el montaje procedemos a programar el uControlador, realmente es un programa muy sencillo, algo monótono y de mucho ctrl+c ctrl+v

 

 




void setup() {
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, INPUT);  
}
 
int val=0;
int num;
void loop() {
                
/*
cero();
 
delay(1000);
 
uno();
 
delay(1000);
dos();
 
delay(1000);
tres();
 
delay(1000);
cuatro();
 
delay(1000);
cinco();
 
delay(1000);
seis();
 
delay(1000);
siete();
 
delay(1000);
ocho();
 
delay(1000);
nueve();
 
delay(1000);
off();
delay(1000);
*/
serpiente();
val=digitalRead(5);
if(val==HIGH){
 num=random(0,10);
 
if(num==0){
 cero();
 delay(500);
 off();
}else if(num==1){
uno();
delay(500);
 off();
} else if(num==2){
dos();
delay(500);
 off();
}else if(num==3){
 tres();
 delay(500);
 off();
} else if(num==4){
 cuatro();
 delay(500);
 off();
}else if(num==5){
 cinco();
 delay(500);
 off();
} else if(num==6){
 seis();
 delay(500);
 off();
} else if(num==7){
 siete();
 delay(500);
 off();
} else if(num==8){
 ocho();
 delay(500);
 off();
}else if(num==9){
 nueve();
 delay(500);
 off();
}    
   
}
}
 
 
void cero(){
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
digitalWrite(8,LOW);
digitalWrite(7,HIGH);
digitalWrite(6,HIGH);
}
 
void uno(){
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
}
 
void dos(){
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,HIGH);
digitalWrite(7,HIGH);
digitalWrite(6,HIGH);
}
 
void tres(){
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,HIGH);
digitalWrite(7,LOW);
digitalWrite(6,HIGH);
}
 
void cuatro(){
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
}
 
void cinco(){
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
digitalWrite(7,LOW);
digitalWrite(6,HIGH);
}
 
void seis(){
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
digitalWrite(7,HIGH);
digitalWrite(6,HIGH);
}
 
void siete(){
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
}
 
void ocho(){
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
digitalWrite(7,HIGH);
digitalWrite(6,HIGH);
}
 
void nueve(){
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
digitalWrite(7,LOW);
digitalWrite(6,HIGH);
}
 
void serpiente(){
digitalWrite(13,HIGH);
delay(200);
digitalWrite(13,LOW);  
digitalWrite(9,HIGH);  
delay(200);
digitalWrite(9,LOW);
digitalWrite(7,HIGH);  
delay(200);
digitalWrite(7,LOW);
digitalWrite(6,HIGH);  
delay(200);
digitalWrite(6,LOW);
digitalWrite(11,HIGH);  
delay(200);
digitalWrite(11,LOW);
digitalWrite(12,HIGH);  
delay(200);
digitalWrite(12,LOW);
}
 
void off(){
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
}