hola yo tengo un problema similar quiero poner un limite de conteo pero no lo logro
este es mi programa
//DEFINICION BINARIA DE LAS CONSTANTES NUMERICAS
const int cero[4] = {0,0,0,0};
const int uno[4] = {0,0,0,1};
const int dos[4] = {0,0,1,0};
const int tres[4] = {0,0,1,1};
const int cuatro[4] = {0,1,0,0};
const int cinco[4] = {0,1,0,1};
const int seis[4] = {0,1,1,0};
const int siete[4] = {0,1,1,1};
const int ocho[4] = {1,0,0,0};
const int nueve[4] = {1,0,0,1};
//DEFINICION DE LOS BOTONES DE ACCION
const int up=19;
const int down=18 ;
//VARIABLES DE ENLACE CON EL DECODIFICADOR 7447
int unidades[4]={0,0,0,0};
int decenas[4]={0,0,0,0};
int centenas[4]={0,0,0,0};
int millares[4]={0,0,0,0};
//VALORES INICIALES PARA LOS DISPLAYS
int millar=0, centena=0, decena=1, unidad=0;
//VARIABLE TRANSITORIA PARA LOS VECTORES
int i,j,k;
void setup() {
//SALIDAS DE LAS UNIDADES
for(i=2;i<=5;i++){
pinMode(i,OUTPUT);
}
//SALIDAS DE LA DECENAS
for(i=6;i<=9;i++){
pinMode(i,OUTPUT);
}
//SALIDAS DE LAS CENTENAS
for(i=10;i<=13;i++){
pinMode(i,OUTPUT);
}
//SALIDAS DE LOS MILLARES
for(i=14;i<=17;i++){
pinMode(i,OUTPUT);
}
//ENTRADAS
pinMode(up,INPUT);
pinMode(down,INPUT);
Serial.begin(9600);
}
void loop() {
if(digitalRead(up)==HIGH){
unidad++;
delay(200);
if(unidad==10){
decena++;
unidad=0;
}
if(decena==10){
centena++;
decena=0;
}
if(centena==10){
millar=0;
centena=0;
}
if(millar==10){
unidad=0;
decena=0;
centena=0;
millar=0;
}
}
if(digitalRead(down)==HIGH){
unidad--;
delay(200);
if(unidad==-1){
decena--;
unidad=9;
}
if(decena==-1){
centena--;
decena=9;
}
if(centena==-1){
millar--;
centena=9;
}
if(millar==-1){
unidad=9;
decena=9;
centena=9;
millar=9;
}
}
switch(millar){
case 0: for(j=0;j<4;j++)millares[j]=cero[j];
break;
case 1: for(j=0;j<4;j++)millares[j]=uno[j];
break;
case 2: for(j=0;j<4;j++)millares[j]=dos[j];
break;
case 3: for(j=0;j<4;j++)millares[j]=tres[j];
break;
case 4: for(j=0;j<4;j++)millares[j]=cuatro[j];
break;
case 5: for(j=0;j<4;j++)millares[j]=cinco[j];
break;
case 6: for(j=0;j<4;j++)millares[j]=seis[j];
break;
case 7: for(j=0;j<4;j++)millares[j]=siete[j];
break;
case 8: for(j=0;j<4;j++)millares[j]=ocho[j];
break;
case 9: for(j=0;j<4;j++)millares[j]=nueve[j];
break;
case 10: for(j=0;j<4;j++)millares[j]=cero[j];
break;
}
switch(centena){
case 0: for(j=0;j<4;j++)centenas[j]=cero[j];
break;
case 1: for(j=0;j<4;j++)centenas[j]=uno[j];
break;
case 2: for(j=0;j<4;j++)centenas[j]=dos[j];
break;
case 3: for(j=0;j<4;j++)centenas[j]=tres[j];
break;
case 4: for(j=0;j<4;j++)centenas[j]=cuatro[j];
break;
case 5: for(j=0;j<4;j++)centenas[j]=cinco[j];
break;
case 6: for(j=0;j<4;j++)centenas[j]=seis[j];
break;
case 7: for(j=0;j<4;j++)centenas[j]=siete[j];
break;
case 8: for(j=0;j<4;j++)centenas[j]=ocho[j];
break;
case 9: for(j=0;j<4;j++)centenas[j]=nueve[j];
break;
case 10: for(j=0;j<4;j++)centenas[j]=cero[j];
break;
}
switch(decena){
case 0: for(j=0;j<4;j++)decenas[j]=cero[j];
break;
case 1: for(j=0;j<4;j++)decenas[j]=uno[j];
break;
case 2: for(j=0;j<4;j++)decenas[j]=dos[j];
break;
case 3: for(j=0;j<4;j++)decenas[j]=tres[j];
break;
case 4: for(j=0;j<4;j++)decenas[j]=cuatro[j];
break;
case 5: for(j=0;j<4;j++)decenas[j]=cinco[j];
break;
case 6: for(j=0;j<4;j++)decenas[j]=seis[j];
break;
case 7: for(j=0;j<4;j++)decenas[j]=siete[j];
break;
case 8: for(j=0;j<4;j++)decenas[j]=ocho[j];
break;
case 9: for(j=0;j<4;j++)decenas[j]=nueve[j];
break;
case 10: for(j=0;j<4;j++)decenas[j]=cero[j];
break;
}
switch(unidad){
case 0: for(j=0;j<4;j++)unidades[j]=cero[j];
break;
case 1: for(j=0;j<4;j++)unidades[j]=uno[j];
break;
case 2: for(j=0;j<4;j++)unidades[j]=dos[j];
break;
case 3: for(j=0;j<4;j++)unidades[j]=tres[j];
break;
case 4: for(j=0;j<4;j++)unidades[j]=cuatro[j];
break;
case 5: for(j=0;j<4;j++)unidades[j]=cinco[j];
break;
case 6: for(j=0;j<4;j++)unidades[j]=seis[j];
break;
case 7: for(j=0;j<4;j++)unidades[j]=siete[j];
break;
case 8: for(j=0;j<4;j++)unidades[j]=ocho[j];
break;
case 9: for(j=0;j<4;j++)unidades[j]=nueve[j];
break;
}
for(k=2;k<=5;k++){digitalWrite(k,unidades[k-2]);}
for(k=6;k<=9;k++){digitalWrite(k,decenas[k-6]);}
for(k=10;k<=13;k++){digitalWrite(k,centenas[k-10]);}
for(k=14;k<=17;k++){digitalWrite(k,millares[k-14]);}
for(k=0;k<4;k++){Serial.print(decenas[k]);}
Serial.print(" ");
for(k=0;k<4;k++){Serial.println(unidades[k]);}
}