int DATAA = 8;
int DATAB = 9;
int DATAC = 10;
int DATAD = 11;
int TRIWARC = A2;
int TRIBAND = 13;
int AUTO = A3;
//-----------------------------
int M160 = A5;
int M80 = A4;
int M40 = A0;
int M30 = A1;
int M20 = 2;
int M17 = 3;
int M15 = 4;
int M12 = 5;
int M10 = 6;
int M6 = 7;
//-------------------------------
int VValorBCD;
//-------------------------------
void setup(){
pinMode (DATAA, INPUT);
pinMode (DATAB, INPUT);
pinMode (DATAC, INPUT);
pinMode (DATAD, INPUT);
pinMode (TRIWARC, INPUT);
pinMode (TRIBAND, INPUT);
pinMode (AUTO, INPUT);
//-------------------------------
pinMode (M160, OUTPUT);
pinMode (M80, OUTPUT);
pinMode (M40, OUTPUT);
pinMode (M30, OUTPUT);
pinMode (M20, OUTPUT);
pinMode (M17, OUTPUT);
pinMode (M15, OUTPUT);
pinMode (M12, OUTPUT);
pinMode (M10, OUTPUT);
pinMode (M6, OUTPUT);
}
void loop(){
// 0 0 0 1 1 160M
// 0 0 1 0 2 80M
// 0 0 1 1 3 40M
// 0 1 0 0 4 30M
// 0 1 0 1 5 20M
// 0 1 1 0 6 17M
// 0 1 1 1 7 15M
// 1 0 0 0 8 12M
// 1 0 0 1 9 10M
// 1 0 1 0 A 6M
VValorBCD=LeerBCDDecimal(DATAA,DATAB,DATAC,DATAD);
if (VValorBCD==0 || VValorBCD==11 || VValorBCD==12||VValorBCD==13|| VValorBCD==14||VValorBCD==15){
digitalWrite (M160,LOW);
digitalWrite (M80,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//160
if (VValorBCD==1){
digitalWrite (M160,HIGH);
digitalWrite (M80,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//80 METROS
if (VValorBCD==2){
digitalWrite (M80,HIGH);
digitalWrite (M160,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//40 METROS
if (VValorBCD==3){
digitalWrite (M40,HIGH);
digitalWrite (M160,LOW);
digitalWrite (M80,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//30 METROS
if ((VValorBCD==4) && (TRIWARC==0)){
digitalWrite (M30,HIGH);
digitalWrite (M160,LOW);
digitalWrite (M80,LOW);
digitalWrite (M40,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//20 METROS
if ((VValorBCD==5) && (TRIBAND==0)){
digitalWrite (M20,HIGH);
digitalWrite (M160,LOW);
digitalWrite (M80,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//17 METROS
if ((VValorBCD==6) && (TRIWARC==0)){
digitalWrite (M17,HIGH);
digitalWrite (M160,LOW);
digitalWrite (M80,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//15 METROS
if ((VValorBCD==7) && (TRIBAND==0)){
digitalWrite (M15,HIGH);
digitalWrite (M160,LOW);
digitalWrite (M80,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M12,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//12 METROS
if ((VValorBCD==8) && (TRIWARC==0)){
digitalWrite (M12,HIGH);
digitalWrite (M80,LOW);
digitalWrite (M160,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//10 METROS
if ((VValorBCD==9) && (TRIBAND==0)){
digitalWrite (M10,HIGH);
digitalWrite (M80,LOW);
digitalWrite (M160,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M6,LOW);
}
//6 METROS
if (VValorBCD==10){
digitalWrite (M6,HIGH);
digitalWrite (M80,LOW);
digitalWrite (M160,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M10,LOW);
}
//3_WARC = 1 ---------------------------------
//30 METROS
if ((VValorBCD==4) && (TRIWARC==1)){
digitalWrite (M12,HIGH);
digitalWrite (M160,LOW);
digitalWrite (M80,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//17 METROS
if ((VValorBCD==6) && (TRIWARC==1)){
digitalWrite (M12,HIGH);
digitalWrite (M160,LOW);
digitalWrite (M80,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//12 METROS
if ((VValorBCD==6) && (TRIWARC==1)){
digitalWrite (M12,HIGH);
digitalWrite (M160,LOW);
digitalWrite (M80,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M10,LOW);
digitalWrite (M6,LOW);
}
//3_BAND = 1---------------------------------
//20 METROS
if ((VValorBCD==5) && (TRIBAND==1)){
digitalWrite (M10,HIGH);
digitalWrite (M80,LOW);
digitalWrite (M160,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M6,LOW);
}
//15 METROS
if ((VValorBCD==7) && (TRIBAND==1)){
digitalWrite (M10,HIGH);
digitalWrite (M80,LOW);
digitalWrite (M160,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M6,LOW);
}
//10 METROS
if ((VValorBCD==9) && (TRIBAND==1)){
digitalWrite (M10,HIGH);
digitalWrite (M80,LOW);
digitalWrite (M160,LOW);
digitalWrite (M40,LOW);
digitalWrite (M30,LOW);
digitalWrite (M20,LOW);
digitalWrite (M17,LOW);
digitalWrite (M15,LOW);
digitalWrite (M12,LOW);
digitalWrite (M6,LOW);
}
}
int LeerBCDDecimal(int DATAA,int DATAB,int DATAC,int DATAD){
int ValorDecimal;
int DATa;
int DATb;
int DATc;
int DATd;
DATa=digitalRead(DATAA);
DATb=digitalRead(DATAB);
DATc=digitalRead(DATAC);
DATd=digitalRead(DATAD);
if((DATa==0) && (DATb=0) && (DATc==0) && (DATd==0)){
ValorDecimal=0;
}
if((DATa==1) && (DATb=0) && (DATc==1) && (DATd==1)){
ValorDecimal=0;
}
if((DATa==0) && (DATb=0) && (DATc==0) && (DATd==0)){
ValorDecimal=11;
}
if((DATa==1) && (DATb=1) && (DATc==0) && (DATd==0)){
ValorDecimal=12;
}
if((DATa==1) && (DATb=1) && (DATc==0) && (DATd==1)){
ValorDecimal=13;
}
if((DATa==1) && (DATb=1) && (DATc==1) && (DATd==0)){
ValorDecimal=14;
}
if((DATa==1) && (DATb=1) && (DATc==1) && (DATd==1)){
ValorDecimal=15;
}
if((DATa==0) && (DATb=0) && (DATc==0) && (DATd==1)){
ValorDecimal=1;
}
if((DATa==0) && (DATb=0) && (DATc==1) && (DATd==0)){
ValorDecimal=2;
}
if((DATa==0) && (DATb=0) && (DATc==1) && (DATd==1)){
ValorDecimal=3;
}
if((DATa==0) && (DATb=1) && (DATc==0) && (DATd==0)){
ValorDecimal=4;
}
if((DATa==0) && (DATb=1) && (DATc==0) && (DATd==1)){
ValorDecimal=5;
}
if((DATa==0) && (DATb=1) && (DATc==1) && (DATd==0)){
ValorDecimal=6;
}
if((DATa==0) && (DATb=1) && (DATc==1) && (DATd==1)){
ValorDecimal=7;
}
if((DATa==1) && (DATb=0) && (DATc==0) && (DATd==0)){
ValorDecimal=8;
}
if((DATa==1) && (DATb=0) && (DATc==0) && (DATd==1)){
ValorDecimal=9;
}
if((DATa==1) && (DATb=0) && (DATc==1) && (DATd==0)){
ValorDecimal=10;
}
return ValorDecimal;
//y así con todos los valores posibles decimales posibles que pueden llegarte por tus entradas para ahorrarte tener que poner en los If unas burradas de condiciones.
}