7 segments display counter:How to tell Arduino not to display the 0 placeholder


hello all! i'm working on counter using 2 double digit 7 segments modules. displays 0 9999 , again. got working, don't know how turn off specific digits if number displayed hasn't gotten of place values (tens place, hundreds place, thousands place). example: (tens place, hundreds place, thousands place). example:

    display 1    :   would display          0  0  0  1           , instead of 1
    display 123:   would display          0  1  2  3           , instead of 123

below full code:

code: [select]

#define pattern_count 11 //number of segment patterns, 0-9 , off
#define segment_count 7  //how many segments i'm controlling
#define digit_count  4   //how many digits i'm controlling



            //                    a,b,c,d,e,f,g
int segmentpins[segment_count] = {2,3,4,5,6,7,8};

//pins each digit
int digitpins[] = { 9, 10, 11, 12 };
//                                          0      1     2    3      4     5     6     7    8     9     off
byte digitpatternshex[pattern_count] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x00 };

//counter
int counter = 0;

void setup(){
 
    //init segment pins output
    for(int thispin=0; thispin<segment_count; thispin++){
      pinmode(segmentpins[thispin], output);
    }

    //init digit pins output
    for(int thispin=0; thispin<digit_count; thispin++){
      pinmode(digitpins[thispin], output);
    }
}
 
//turn digits off, high because common cathode
void alldigitsoff(){
  for(int thispin = 0; thispin < digit_count; thispin++){
    digitalwrite(digitpins[thispin], high);
  }
}

//turn specific digit on
void digiton(int digitnum){
 
  digitalwrite(digitpins[digitnum], low);
 
  delay(2);
}


void setpattern(int pattern){
  alldigitsoff();
 
  //data pins, 8bits
    for(int thispin=0; thispin<segment_count; thispin++){
      if(bitread(digitpatternshex[pattern], thispin) == 1){
        digitalwrite(segmentpins[thispin], high);
      }else{
        digitalwrite(segmentpins[thispin], low);
      }
    }
 
}

void shownumber(int currentnumber){
 
  //display digit right left
  int digitinfront = currentnumber/10;
  for(int currentdigit = 0; currentdigit < digit_count; currentdigit++){
   
    //get number in ones place
    int number = currentnumber % 10; //5
   
    currentnumber /= 10;

    setpattern(number);
   
    digiton(currentdigit);
       
  }
}

void loop(){
 
//return first 2 digits of ms, 1 sec = 1000 millisec, 1.5 sec = 1500 millisec
 
  int currentnumber = (millis()/1000);
 
  shownumber(currentnumber);
}



they're called "leading zeros" fyi. school assignment?


Arduino Forum > Using Arduino > Programming Questions > 7 segments display counter:How to tell Arduino not to display the 0 placeholder


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts