Hi, here I am again and my problem is solved.
When I started this thread, i did not know, how to use the MAX7219 in decodemode 0.
Before i used decodemode 0F, to drive a 4 digit 7 segment display, found in an old
microwave oven. This lost by and by several segments and I had to look for a substitute.
My program test1.ino shows all the necessary ten digits 0 . . 9 and a space, which I need for my clock.
The double colon between the hours ones and the minutes tens are two extra leds, controlled by UNO port 18.
The array consists of 4 columns and 7 rows, so one MAX can drive 2 digits. In this case only 26 leds are necessary, two are not used.
/* test1.ino
an array with 4x7 leds displays the digits 0.. 9 + space
the leds are wired as common cathode to replace a 7 segment display
as well as in my first program test.ino
*/
#define digit10 space
byte const digits_font [11][7] PROGMEM = {
{ 0x06, 0x09, 0x09, 0x09, 0x09, 0x09, 0x06 }, // 0
{ 0x02, 0x06, 0x02, 0x02, 0x02, 0x02, 0x07 }, // 1
{ 0x06, 0x09, 0x01, 0x02, 0x04, 0x08, 0x0F }, // 2
{ 0x0E, 0x01, 0x01, 0x06, 0x01, 0x01, 0x0E }, // 3
{ 0x08, 0x0A, 0x0A, 0x0F, 0x02, 0x02, 0x02 }, // 4
{ 0x0F, 0x08, 0x08, 0x0E, 0x01, 0x01, 0x0E }, // 5
{ 0x07, 0x08, 0x08, 0x0E, 0x09, 0x09, 0x06 }, // 6
{ 0x0F, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08 }, // 7
{ 0x06, 0x09, 0x09, 0x06, 0x09, 0x09, 0x06 }, // 8
{ 0x06, 0x09, 0x09, 0x07, 0x01, 0x01, 0x0E }, // 9
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // = space
};
const byte ledPin = 19;
bool ledState = LOW;
unsigned long previousMillis = 0;
const unsigned long interval = 500;
unsigned long previousMillis1;
const unsigned long interval_1 = 10;
#include <SPI.h>
const byte MAX7219_REG_NOOP = 0x0;
const byte MAX7219_REG_DIGIT0 = 0x1; // 1. LED-Reihe
const byte MAX7219_REG_DIGIT1 = 0x2;
const byte MAX7219_REG_DIGIT2 = 0x3;
const byte MAX7219_REG_DIGIT3 = 0x4;
const byte MAX7219_REG_DIGIT4 = 0x5;
const byte MAX7219_REG_DIGIT5 = 0x6;
const byte MAX7219_REG_DIGIT6 = 0x7;
const byte MAX7219_REG_DIGIT7 = 0x8; // 8. LED-Reihe
const byte MAX7219_REG_DECODEMODE = 0x9;
const byte MAX7219_REG_INTENSITY = 0xA;
const byte MAX7219_REG_SCANLIMIT = 0xB;
const byte MAX7219_REG_SHUTDOWN = 0xC;
const byte MAX7219_REG_DISPLAYTEST = 0xF;
void setup() {
Serial.begin(115200);
Serial.println("=======================================");
Serial.println("======= 4x7.ino ======================");
Serial.println("======================== 12.1.22 =======");
SPI.begin();
pinMode(ledPin, OUTPUT);
sendByte (MAX7219_REG_SCANLIMIT, 7); // all, 0 ... 7
sendByte (MAX7219_REG_DECODEMODE, 0); // single LED
sendByte (MAX7219_REG_DISPLAYTEST, 0); // Anzeige=0, Test=1
sendByte (MAX7219_REG_INTENSITY, 0); // 0 .. 15
sendByte (MAX7219_REG_SHUTDOWN, 1); // 1 = KEIN Abschalten
for (byte col = 0; col < 8; col++) // clear Display
{
sendByte(col + 1, 0);
}
}
void sendByte(const byte reg, const byte data)
{ digitalWrite(SS, LOW);
SPI.transfer (reg);
SPI.transfer (data);
digitalWrite(SS, HIGH);
}
void digit (const byte c) // only 7 rows!!
{
for (byte col = 0; col < 7; col++)
sendByte (col + 1, pgm_read_byte (&digits_font [c] [col]));
}
void clear() {
for (byte col = 0; col < 8; col++) // clear Display
{
sendByte(col + 1, 0);
}
}
void blink() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{ previousMillis = currentMillis;
ledState == LOW ? ledState = HIGH : ledState = LOW;
digitalWrite(ledPin, ledState);
}
}
void loop() { //===========================================
static uint16_t count;
blink();
for (byte k = 0; k < 11; k++)
{ digit(k);
Serial.print(k);
delay(1000);
}
// clear();
count++;
Serial.print(" LOOP : "); Serial.print(count);
Serial.println();
}
I thank you all for the replies to my thread. I am still learning every day.
Sincerely bolsak.