Hello,
I needed to use a common anode 7 segments display with a MAX7219 chip, which is supposed to work with common cathode.
I find older posts about it, but without really simple software solutions. So I wanted to share what I did.
It's in fact quite easy to drive a common anode display with LedControl library.
First, as said in older posts, wiring has to be swapped between digit pins and segment pins.
DIG1 to DIG7 MAX7219 pins have to be wired to segments a to g of the displays.
SEG A to SEG F pins have to be wired to digit 1, digit 2, etc...
Then with LedControl library you could use setColumn function to display digits, with the character table defined in the header :
void print(byte d,byte n)
{
lc.setColumn(0,d,pgm_read_byte_near(charTable + n));
}
This function print n on digit (display) d. Example :
print(1,5) displays '5' on the first digit
n values from 0 to 15 display 0...9 then A...F.
Here is a code to count from 0 to 99 on a 2 digit display (Arduino Uno) :
#include "LedControl.h"
/*
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
*/
LedControl lc=LedControl(12,11,10,1);
void print(byte d,byte n)
{
lc.setColumn(0,d,pgm_read_byte_near(charTable + n));
}
void setup()
{
lc.shutdown(0,false);
lc.setIntensity(0,9); // 0 to 15
lc.clearDisplay(0);
}
void loop()
{
for(byte i=0;i<100;i++)
{
print(1,i/10); //tens
print(2,i%10); //ones
delay(1000);
}
}
Regards
Pierre