Counter that can go up and down

I want to make a counter that can go up and down I already can let it go up but i’m stuck with letting it go down

This is the code that I use to let it go up but I want to make it that when my input is HIGH it goes down from where I am. Any advice?

for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
for(int k=0;k<10;k++){
for(int l=0;l<10;l++){

-- (two minus signs) is the decrement operator.

Try:

for (int i = 10; i >= 0; i--)

But my problem is that when I push a button I want that it immediately changes to the downcounter that starts from the point where my upcounter stopped, how do I implement this?

It is very difficult to make a useful suggestion without seeing your code. But I’ll try…

 if(digitalRead(myButtonPin)) i++; else i--;

You can leave any element of the for() blank. It is legal to write for(;i <= 10;) or even for(;;) but most people would use a while() loop in those cases.

This is the code I have now but it stops at l=9 and it starts over at 0 again without i,j, or k getting bigger and it doesn’t work when I push the inputbutton, it doesn’t start downcounting

void upCounter(int a, int b, int c, int d){
int i = a;
int j = b;
int k = c;
int l = d;

for(i;i<10;i++){
readInput;
if (inputState == HIGH){
downCounter(i,j,k,l);
}

for(j;j<10;j++){
readInput;
if (inputState == HIGH){
downCounter(i,j,k,l);
}

for(k;k<10;k++){
readInput;
if (inputState == HIGH){
downCounter(i,j,k,l);
}

for(l;l<10;l++){
readInput;
if (inputState == HIGH){
downCounter(i,j,k,l);
}

for (int m=0;m<20;m++){
digitalWrite(CC[0], LOW);
digitalWrite(CC[1], HIGH);
digitalWrite(CC[2], HIGH);
digitalWrite(CC[3], HIGH);
showNumber(l);
delay(5);

digitalWrite(CC[0], HIGH);
digitalWrite(CC[1], LOW);
digitalWrite(CC[2], HIGH);
digitalWrite(CC[3], HIGH);
showNumber(k);
delay(5);

digitalWrite(CC[0], HIGH);
digitalWrite(CC[1], HIGH);
digitalWrite(CC[2], LOW);
digitalWrite(CC[3], HIGH);
showNumber(j);
delay(5);

digitalWrite(CC[0], HIGH);
digitalWrite(CC[1], HIGH);
digitalWrite(CC[2], HIGH);
digitalWrite(CC[3], LOW);
showNumber(i);
delay(5);
}
}
}
}
}
i=0;
j=0;
k=0;
l=0;
}

void downCounter(int a, int b, int c, int d){
int i = a;
int j = b;
int k = c;
int l = d;

for(i;i>0;i–){
readInput;
if (inputState == LOW){
upCounter(i,j,k,l);
}

for(j;j>0;j–){
readInput;
if (inputState == LOW){
upCounter(i,j,k,l);
}
for(k;k>0;k–){
readInput;
if (inputState == LOW){
upCounter(i,j,k,l);
}

for(l;l>0;l–){
readInput;
if (inputState == LOW){
upCounter(i,j,k,l);
}

for (int m=0;m<20;m++){
digitalWrite(CC[0], LOW);
digitalWrite(CC[1], HIGH);
digitalWrite(CC[2], HIGH);
digitalWrite(CC[3], HIGH);
showNumber(l);
delay(5);

digitalWrite(CC[0], HIGH);
digitalWrite(CC[1], LOW);
digitalWrite(CC[2], HIGH);
digitalWrite(CC[3], HIGH);
showNumber(k);
delay(5);

digitalWrite(CC[0], HIGH);
digitalWrite(CC[1], HIGH);
digitalWrite(CC[2], LOW);
digitalWrite(CC[3], HIGH);
showNumber(j);
delay(5);

digitalWrite(CC[0], HIGH);
digitalWrite(CC[1], HIGH);
digitalWrite(CC[2], HIGH);
digitalWrite(CC[3], LOW);
showNumber(i);
delay(5);
}
}
}
}
}
i=0;
j=0;
k=0;
l=0;
}

void loop() {
upCounter(0,0,0,0);
}

Ok. Next time use code tags (read how-to-use-this-forum.)

First, function arguments are usually passed by value, which means that downCounter() cannot affect the values of ijk in upCounter().

Second, calling a function is a temporary thing. The function does some job and then returns to the caller. There is a "stack" which remembers who called who and where to resume in each caller. So your program will overflow and break the stack with enough up-down-up calls.

Third, this looks like homework. We will teach you how to fish but we won't give your professor the fish.