Arduino counter

hi

i’m trying to make a counter using the arduino. i am using a 4 digit LED display. what is supposed to happen is that when a button is pressed, the number on the display increases by one. I got it to work for single digit #s(0 to 9), but i can figure out how to get it to display bigger numbers. I know how to multiplex but i can’t figure it out. I’ve tried getting a second counter variable to increase by one every time the first one hits zero.

any help would be appreciated.

thanks

int counter;
int counter2;
int counter3;


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,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(2,INPUT);
  Serial.begin(9600);

}





        void zero(){
 digitalWrite(7,HIGH);
 digitalWrite(3,HIGH);
 digitalWrite(11,HIGH);
 digitalWrite(12,HIGH);
 digitalWrite(13,HIGH);
 digitalWrite(6,HIGH);
 digitalWrite(10,LOW);
        }
        
        void one(){
 digitalWrite(7,LOW);
 digitalWrite(3,HIGH);
 digitalWrite(11,HIGH);
 digitalWrite(12,LOW);
 digitalWrite(13,LOW);
 digitalWrite(6,LOW);
 digitalWrite(10,LOW);
        }     
        
        void two(){
        digitalWrite(7,HIGH);
 digitalWrite(3,HIGH);
 digitalWrite(11,LOW);
 digitalWrite(12,HIGH);
 digitalWrite(13,HIGH);
 digitalWrite(6,LOW);
 digitalWrite(10,HIGH);
        }
        
        void three(){
       digitalWrite(7,HIGH);
 digitalWrite(3,HIGH);
 digitalWrite(11,HIGH);
 digitalWrite(12,HIGH);
 digitalWrite(13,LOW);
 digitalWrite(6,LOW);
 digitalWrite(10,HIGH);
        }
        
        void four(){
 digitalWrite(7,LOW);
 digitalWrite(3,HIGH);
 digitalWrite(11,HIGH);
 digitalWrite(12,LOW);
 digitalWrite(13,LOW);
 digitalWrite(6,HIGH);
 digitalWrite(10,HIGH);
        }
        
        void five(){
       digitalWrite(7,HIGH);
 digitalWrite(3,LOW);
 digitalWrite(11,HIGH);
 digitalWrite(12,HIGH);
 digitalWrite(13,LOW);
 digitalWrite(6,HIGH);
 digitalWrite(10,HIGH);
        }
        
        void six(){
        digitalWrite(7,HIGH);
 digitalWrite(3,LOW);
 digitalWrite(11,HIGH);
 digitalWrite(12,HIGH);
 digitalWrite(13,HIGH);
 digitalWrite(6,HIGH);
 digitalWrite(10,HIGH);
        }
        
        void seven(){
        digitalWrite(7,HIGH);
 digitalWrite(3,HIGH);
 digitalWrite(11,HIGH);
 digitalWrite(12,LOW);
 digitalWrite(13,LOW);
 digitalWrite(6,LOW);
 digitalWrite(10,LOW);
        }
       
        void eight(){
        digitalWrite(7,HIGH);
 digitalWrite(3,HIGH);
 digitalWrite(11,HIGH);
 digitalWrite(12,HIGH);
 digitalWrite(13,HIGH);
 digitalWrite(6,HIGH);
 digitalWrite(10,HIGH);
        }
        
        void nine(){
      digitalWrite(7,HIGH);
 digitalWrite(3,HIGH);
 digitalWrite(11,HIGH);
 digitalWrite(12,HIGH);
 digitalWrite(13,LOW);
 digitalWrite(6,HIGH);
 digitalWrite(10,HIGH);
              }


void digit1(){
    digitalWrite(9,LOW);
  digitalWrite(4,HIGH);
  digitalWrite(5,HIGH);
  digitalWrite(8,HIGH);
}

void digit2(){
    digitalWrite(9,HIGH);
  digitalWrite(4,LOW);
  digitalWrite(5,HIGH);
  digitalWrite(8,HIGH);
}

void digit3(){
    digitalWrite(9,HIGH);
  digitalWrite(4,HIGH);
  digitalWrite(5,LOW);
  digitalWrite(8,HIGH);
}

void digit4(){
    digitalWrite(9,HIGH);
  digitalWrite(4,HIGH);
  digitalWrite(5,HIGH);
  digitalWrite(8,LOW);
}







void singleDigit(){
  for(counter=0;counter<9;){
    if(digitalRead(2) == LOW){
     
        counter++;
        counter3 == counter;
    
    }
    
    switch(counter){
      
      case 0:
      digit1();
      zero();
      break;
      
      case 1:
      digit1();
      one();
      break;
      
      case 2:
      digit1();
      two();
      break;
      
      case 3:
      digit1();
      three();
      break;
      
      case 4:
      digit1();
      four();
      break;
      
      case 5:
      digit1();
      five();
      break;
      
      case 6:
      digit1();
      six();
      break;
      
      case 7:
      digit1();
      seven();
      break;
      
      case 8:
      digit1();
      eight();
      break;
      
      case 9:
      digit1();
      nine();
      break;
    }
  }
}



void doubleDigit(){
  for(counter2=0;counter2<9;){
    if (counter3 = 0){
      counter2++;
    }
    
    switch(counter2){
      
      case 0:
      digit2();
      zero();
      break;
      
      case 1:
      digit2();
      one();
      break;
      
      case 2:
      digit2();
      two();
      break;
      
      case 3:
      digit2();
      three();
      break;
      
      case 4:
      digit2();
      four();
      break;
      
      case 5:
      digit2();
      five();
      break;
      
      case 6:
      digit2();
      six();
      break;
      
      case 7:
      digit2();
      seven();
      break;
      
      case 8:
      digit2();
      eight();
      break;
      
      case 9:
      digit2();
      nine();
      break;
    }
  }
}


void loop(){

  singleDigit();
  delay(2);
  doubleDigit();
  delay(2);
  
}
if (counter3 = 0){

Does that look right? Not saying that's the whole problem, but it does need fixing.

Also, when you get some time, have a look at arrays. Arrays can make your sketch cleaner and easier to work with.

in a nutshell what you do is divide each place by its place, and treat each one as a single number as long as they are integers the results should be round numbers (not 1.435)
ie:

number = 1234

number / 1000 = 1
number / 100  = 2
number / 10   = 3
number / 1    = 4

you may also want to look into how to use for loops and arrays, they save you tons of writing out redundant code, run faster and are easier to debug once you get the hang of them

http://arduino.cc/en/Reference/For
http://arduino.cc/en/Reference/Array