Digits

Quick question: if you have say a 4-digit 7-segment led, is it possible to show numbers on the right 3 and leave the left digit not lit up?

AndyInSurrey:
Quick question: if you have say a 4-digit 7-segment led, is it possible to show numbers on the right 3 and leave the left digit not lit up?

Even quicker answer: yes

Even when using a multiplex chip i.e. MAX7219 and using the LedControl library?

AndyInSurrey:
Even when using a multiplex chip i.e. MAX7219 and using the LedControl library?

Yes. In fact that library has a setChar() function which can take an ASCII character and set a digit to 0 to 9, plus a few letters of the alphabet and some symbols as well as translating a space to blank. You could combine this with sprintf() to make your code very short and neat. sprintf() is not part of the ledControl library. it is a function that is available in the Arduino language, but is not mentioned on the reference page.

Example:

char s[5];
int score = 42;
sprintf(s, "%4d", score);
for (int i=0; i<4; i++) setChar(0, i, s[i], false);

Thank you. I had been using the setDigit() function and had overlooked the setChar() function. I'll update my code soon.

I know all about sprintf(). I program for a living in C and C++.

AndyInSurrey:
I program for a living in C and C++.

Oh yes, you did say before, sorry. I'll remember that when i get stuck with tricky C++ next time. I work in retail logistics management these days but was also a programmer for many years. Did some C and various OO languages and modelling techniques over the years and every language from Ada to VBA, but still have a few lessons to learn in C++.

AndyInSurrey:
Even when using a multiplex chip i.e. MAX7219 and using the LedControl library?

Well, clearly this is only ever a software matter; the MAX7219 will generate any pattern at all that you instruct it to. If there were a limitation to the LedControl library, the obvious solution would be to simply avoid the library and code it yourself, which is hardly difficult.

The only likely limitation is in fact whether the library is limited to the character generator mode of the MAX7219 which constrains you to common cathode LEDs, or whether it generates the font itself in which case there is no such restriction. I have not found a reason to use that library, so do not know offhand. :grinning:

I just wrote code, today, to do that very thing. I wanted to remove leading zeroes from the display.

  blanking = true;  // Waiting for non-zero digit
  
  for (i = 7; i >= 0; i--) {
    if (digits[i] > 0) blanking = false;
    if (blanking)  
      mydisplay.setChar(0, i, ' ',false);  // blank a digit position
    else
      mydisplay.setDigit(0, i, digits[i], false);
  }

MikeyMoMo:
I just wrote code, today, to do that very thing. I wanted to remove leading zeroes from the display.

  blanking = true;  // Waiting for non-zero digit

for (i = 7; i >= 0; i–) {
    if (digits[i] > 0) blanking = false;
    if (blanking) 
      mydisplay.setChar(0, i, ’ ',false);  // blank a digit position
    else
      mydisplay.setDigit(0, i, digits[i], false);
  }

Hmm, look at PaulRB’s idea to this solution above. The following code does the same as yours but it’s a much neater solution.

MikeyMoMo:
I just wrote code, today, to do that very thing. I wanted to remove leading zeroes from the display.

  blanking = true;  // Waiting for non-zero digit

for (i = 7; i >= 0; i--) {
    if (digits[i] > 0) blanking = false;
    if (blanking) 
      mydisplay.setChar(0, i, ' ',false);  // blank a digit position
    else
      mydisplay.setDigit(0, i, digits[i], false);
  }

Use code tags so you don't lose parts of your code.