7 segment 4 digit common anode works with MAX7219

Just wanted to share my 3 days challenge to make 7 seg common anode work with MAX7219 which designed to work with common cathode displays only. I made base functions to display digits, numbers, letters and words. LedControl lib used:

#include "LedControl.h"
LedControl lc=LedControl(2,4,3,1);

byte dig[]={0b00111111,0b00000110,0b01011011,0b01001111,0b01100110,0b01101101,0b01111101,0b00000111,0b01111111,0b01100111};
byte alp[]={0b01110111,0b01111111,0b00111001,0b01011110,0b01111001,0b01110001,0b00111101,0b01110110,0b00110000,0b00011111,0b01110101,0b00111000,0b00010101,0b00110111,0b00111111,0b01110011,0b01100111,0b00110011,0b01101101,0b01111000,0b00111110,0b00101110,0b00101010,0b01110110,0b01101110,0b01001011};

void setup() {
lc.shutdown(0,false); lc.setIntensity(0,8); lc.clearDisplay(0);
}

void showdigit(int pos,int digit){ for (int i=0; i < 7; i++){if (bitRead(dig[digit],i)) lc.setLed(0,i,pos,true);}}
void showletter(int pos,int digit){ for (int i=0; i < 7; i++){if (bitRead(alp[digit],i)) lc.setLed(0,i,pos,true);}}
void shownumber(int num){ lc.clearDisplay(0); String snum=String(num); for(int i=0;i<snum.length();i++){ int d = (int)snum.charAt(i)-48; showdigit(i+5-snum.length(),d);}}
void showword(String s){ lc.clearDisplay(0); String abc="abcdefghijklmnopqrstuvwxyz";for(int i=0;i<s.length();i++){showletter(i+5-s.length(),abc.indexOf(s.charAt(i)));}}

void loop() { 

// some tests

for(int l=-5;l<21;l++){lc.clearDisplay(0);for(int i=l;i<l+6;i++){ showletter(i-l-1,i);}delay(200);}

showword("one");
delay(500);
showword("two");
delay(500);
showword("thre");
delay(500);
showword("four");
delay(500);

for(int i=0;i<9999;i++){shownumber(i);delay(50);}

}

Sorry for code style and low comments. Image show how to connect Max and display.
I connected DIN to my Arduino digital PIN 2, CLK to PIN 4 and LOAD to PIN 3. Enjoy!

Bitmag:
Just wanted to share my 3 days challenge to make 7 seg common anode work with MAX7219 which designed to work with common cathode displays only.

Well, that is simply nonsense. The MAX7219 does not care whether it is used for common anode or common cathode displays; it works equally well with either. It is simply an 8 by 8 matrix driver.

Sorry to rain on your parade. :roll_eyes: It is true that it has certain functions directed toward common cathode displays, such as a decoder to generate characters "0" to "9" plus "H", "E", "L", "P" and "-" when used with common cathode displays - but you often want to generate other characters and that then becomes less useful. Of course, its registers correspond to cathode drivers and you can restrict their number to better multiplex smaller displays such as the four digits you indicate here, so that makes it less efficient.

In short, it is simply misleading to ever suggest it is in some way "limited" to common cathode displays. But do enjoy yourself with your code. :grinning:

The only thing the OP has proven is that he doesn’t know how to use Google. Here’s the first hit for “using max7219 with common anode display”:

http://www.plingboot.com/2017/01/max7219-and-common-anode-displays/

BTW, the code contained in the link is actually readable and re-usable.

WattsThat:
The only thing the OP has proven is that he doesn’t know how to use Google. Here’s the first hit for “using max7219 with common anode display”:

http://www.plingboot.com/2017/01/max7219-and-common-anode-displays/

BTW, the code contained in the link is actually readable and re-usable.

Yes, I saw that post. But code provided there just did not work for me.

Bitmag:
Yes, I saw that post. But code provided there just did not work for me.

Any idea why?