I forgot : The R set for the MAX7219 current segment limiting is 68 K. A bit higher than the datasheet. I just want the segments to be under 10 mA. During a power-up test ( no Arduino connected ), all leds was light up, so I measured the I total going into the circuit. It was around 100 mA, it is well bellow the Arduino voltage regulator current rating.
I did a code to display a basic patern, ( I am planning to display multi-paterns ), the code is not complete, but it work so far. It miss : mode selection, scrolling speed selection, more paterns and a random patern. The random patern will use an open analog pin value for a random seed value. I will build a noise generator circuit see site : http://www.sentex.ca/~mec1995/tutorial/xtor/xtor6/xtor6.html and check the noise circuit. I breadboard it and I will need to amplify the signal, remove the high frequency component, and use the clean amplify signal for a random voltage to be use by the analog pin. I will post my final circuit. I included a picture of the noise signal. +12 V is use to power the circuit. Any lower, no noise signal. My scope setting is : 50 mV / div , 5 mS / div.
For now, here the code I will use ( tested OK so far ) to display leds chaser paterns using a MAX7219. Some parts is missing. It is not complete yet.
// Output Pins - Data In, Latch pulse and Clock pulse
const byte datapin = 12;
const byte latchpin = 11;
const byte clockpin = 10;
// Input Pins
const byte inpin[4] = {4,5,6,7};
// Analog Pin
const byte anapin = 1;
// Load up the display buffer
byte display_data[8] = {0,0,0,0,0,0,0,0};
// Numbers to Display Code
byte display_number[10] = {0b01111110,0b00110000,0b01101101,0b01111001,0b00110011,0b01011011,0b01011111,0b01110000,0b01111111,0b01110011};
int analog_value = 512;
int delay_rate = 500;
byte the_rate = 50;
byte the_mode = 1;
void setup()
{
// set analog voltage reference origin
analogReference(EXTERNAL);
// Set Output pins
pinMode(datapin, OUTPUT);
pinMode(latchpin, OUTPUT);
pinMode(clockpin, OUTPUT);
// Set Input pins
for (byte i=0;i<4;i++)
{
pinMode(inpin[i], INPUT);
}
// set MAX7219 : Normal Mode
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 0x0C );
shiftOut(datapin, clockpin, MSBFIRST, 0x01 );
digitalWrite(latchpin, HIGH);
delay(5);
// set MAX7219 : Normal Operation
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 0x0F );
shiftOut(datapin, clockpin, MSBFIRST, 0x00 );
digitalWrite(latchpin, HIGH);
delay(5);
// set MAX7219 : Intensity
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 0x0A );
shiftOut(datapin, clockpin, MSBFIRST, 0x0B );
digitalWrite(latchpin, HIGH);
delay(5);
// set MAX7219 : Numbers of digits
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 0x0B );
shiftOut(datapin, clockpin, MSBFIRST, 0x07 );
digitalWrite(latchpin, HIGH);
delay(5);
// set MAX7219 : Decode Mode Register
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 0x09 );
shiftOut(datapin, clockpin, MSBFIRST, 0x00 );
digitalWrite(latchpin, HIGH);
delay(5);
// set display to zero
display_the_max();
}
void loop()
{
get_the_rate();
the_mode = 1;
mode_1_2();
delay(3000);
the_mode = 2;
mode_1_2();
delay(3000);
}
void display_the_max()
{
for (byte i=0; i<8;i++)
{
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, (i+1));
shiftOut(datapin, clockpin, MSBFIRST, display_data[i]);
digitalWrite(latchpin, HIGH);
delay(5);
}
}
void get_the_rate()
{
byte High_nibble;
byte Low_nibble;
delay_rate = int(the_rate) * 10;
High_nibble = the_rate / 10;
Low_nibble = the_rate % 10;
display_data[6] = display_number[High_nibble];
display_data[5] = display_number[Low_nibble];
}
// Shift
void mode_1_2()
{
byte shift_data = 0b10000000;
if (the_mode == 1 )
{
display_data[7] = display_number[1];
for (byte i=0;i<5;i++)
{
display_data[i]=0b00000000;
}
}
if (the_mode == 2 )
{
display_data[7] = display_number[2];
for (byte i=0;i<5;i++)
{
display_data[i]=0b11111111;
}
}
for (int k=4;k>=0;k--)
{
shift_data = 0b10000000;
for(byte j=0;j<8;j++)
{
if (the_mode == 1)
{
display_data[k] = shift_data;
}
if (the_mode == 2)
{
display_data[k] = ~shift_data;
}
display_the_max();
delay(delay_rate);
shift_data = shift_data >> 1;
}
if (the_mode == 1 )
{
display_data[k] = 0b00000000;
}
if (the_mode == 2 )
{
display_data[k] = 0b11111111;
}
}
for (int k=0;k<5;k++)
{
shift_data = 0b00000001;
for(byte j=0;j<8;j++)
{
if (the_mode == 1)
{
display_data[k] = shift_data;
}
if (the_mode == 2)
{
display_data[k] = ~shift_data;
}
display_the_max();
delay(delay_rate);
shift_data = shift_data << 1;
}
if (the_mode == 1)
{
display_data[k] = 0b00000000;
}
if (the_mode == 2)
{
display_data[k] = 0b11111111;
}
}
}
// Grow
void mode_3()
{
display_data[7] = display_number[3];
}
// Grow Invert
void mode_4()
{
display_data[7] = display_number[4];
}
//Chase
void mode_5()
{
display_data[7] = display_number[5];
}
// Chase Invert
void mode_6()
{
display_data[7] = display_number[6];
}
// Random
void mode_7()
{
display_data[7] = display_number[7];
}